', 'tac', 'toe']):
......print(i, v)
...
0 tic
1 tac
2 toe
2
字典item()方法
遍历字典时,如果直接遍历字典对象,只能得到字典中的键:
>>> sample = {'a':1,'b':2,...x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> list(zipped)
[(1, 4), (2, 5), (3, 6)]
当同时在两个或更多序列中循环时...如果设为 True,则每个列表元素将按反向顺序比较进行排序。...print(f)
...
apple
banana
orange
pear
5
reversed()函数
reversed()函数用于对可迭代对象中的元素进行反向排列,返回一个逆向的迭代器。