列表逆序遍历

reversed() 函数

  1. a = ["我", "用", "Python"]
  2. a_r = list(reversed(a))
  3. ## ["Python", "用", "我"]
  4. for i in a_r:
  5. print(i)
  6. ## Python
  7. ## 用
  8. ## 我

字典逆序遍历

zip()

  1. for key, val in zip(list(reversed(list(mydict.keys()))), list(reversed(list(mydict.values())))):
  2. print(key, ":", val)
  3. ## ...
  4. ## key2:value2
  5. ## key1:value1