Python 如何使用len计算出有多少行
使用变量“frame”作为输入,根据列中的数据打印每行的行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 = {'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])不是特别漂亮