遍历
# iterate list
for elem in lst:
print(elem)
for idx, elem in enumerate(lst):
print('Index: {0} element: {1}'.format(idx, elem))
for item in enumerate(lst):
print(item) # item is tuple(index, element)
# iterate dict
for key in a_dict:
print(key, "->", a_dict[key])
for key in a_dict.keys():
print(key, '->', a_dict[key])
for value in a_dict.values():
print(value)
for item in a_dict.items():
print(item) # item is tuple(key, value)
for key, value in a_dict.items():
print(key, '->', value)
new_dict[value] = key