Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用len计算出有多少行_Python_Python 3.x - Fatal编程技术网

Python 如何使用len计算出有多少行

Python 如何使用len计算出有多少行,python,python-3.x,Python,Python 3.x,使用变量“frame”作为输入,根据列中的数据打印每行的行 frame = {'kind of pet': ['dogs', 'cats', 'gerbils', 'geese'], 'number of pets': [10, 20, 5, 4]} 我希望输出看起来像 狗10 猫20 沙鼠5 鹅4 你可以这样做 for a,b, in zip(frame['kind of pet'],frame['number of pets']): print("{} {}".format(b,a))

使用变量“frame”作为输入,根据列中的数据打印每行的行

frame = {'kind of pet': ['dogs', 'cats', 'gerbils', 'geese'],
 'number of pets': [10, 20, 5, 4]}
我希望输出看起来像

狗10 猫20 沙鼠5 鹅4


你可以这样做

for a,b, in zip(frame['kind of pet'],frame['number of pets']):
print("{} {}".format(b,a))

在Python3.x+上使用f字符串以提高易读性

您尝试了什么?你具体需要什么帮助?谢谢你,这很有效。但是有没有办法使用len?当然:对于范围内的i(len(frame['kind-pet']):打印({}{})。格式(frame['kind-pet'][i],frame['number-of-pets'][i])不是特别漂亮