bookshelf = {'name':['1', '2'], 'author': ["First", "Second"]}
if __name__ == '__main__':
for i in range(len(bookshelf.get('name'))):
print(bookshelf['name'][i])
print(bookshelf['author'][i])
bookshelf={'A':['A1','A2'],'B':['B1','B2']}
for i in range(0,2):
print(f"The name of the book is {bookshelf['A'][i]}, the name of the author is {bookshelf['B'][i]} ")
2条答案
按热度按时间0mkxixxg1#
range
中的i
会自动递增,除非您愿意,否则您不必使用i = i + 1
。你就迭代了两次。
ia2d9nvy2#
我尝试了以下方法:
此问题不需要key,value命令。