python字典
- 无序字典(Dict)
my_dict = dict()
my_dict["name"] = "lowman"
my_dict["age"] = 26
my_dict["girl"] = "Tailand"
my_dict["money"] = 80
my_dict["hourse"] = None
for key, value in my_dict.items():
print(key, value)
输出:money 80
girl Tailand
age 26
hourse None
name lowman
但是目前python3.7中无序字典的输出对应输入是有序的。
- 有序字典(OrderDict)
import collections
my_order_dict = collections.OrderedDict()
my_order_dict["name"] = "lowman"
my_order_dict["age"] = 45
my_order_dict["money"] = 998
my_order_dict["hourse"] = None
for key, value in my_order_dict.items():
print(key, value)
输出:name lowman
age 45
money 998
hourse None