Python 3.6 改写了 dict 的内部算法,因此 3.6 的 dict 是有序的,在此版本之前皆是无序的。
# 列表去重
# bulidUrl_list = list(set(list))
# bulidUrl_list.sort(key=list.index)
city_dict= {"nb":"宁波", "nc":"南昌", "km":"昆明", "nn":"南宁", "gy":"贵阳", "nt":"南通", "su":"苏州", "zz":"郑州"}
for keyin city_dict.keys(): # 顺序不变了...
print(key, end=" \t")
print()
for valuein city_dict.values():
print(value, end=" ")
print(“***********************************************************************************”)
in city_dict.items():
print(key +" "+ value)
网友评论