(3, 'Fall'), (4, 'Winter')]
这时候用for循环遍历enumerate()函数包装后的序列,就能得到元素及其索引值:
>>> for i, v in enumerate(['tic...', 'tac', 'toe']):
......print(i, v)
...
0 tic
1 tac
2 toe
2
字典item()方法
遍历字典时,如果直接遍历字典对象,只能得到字典中的键:
>>> sample = {'a':1,'b':2,...2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> list(zipped)
[(1, 4), (2, 5), (3, 6)]
当同时在两个或更多序列中循环时...print(f)
...
apple
banana
orange
pear
5
reversed()函数
reversed()函数用于对可迭代对象中的元素进行反向排列,返回一个逆向的迭代器。