cities_dict ={'Beijing':'China', 'Paris':'France', 'Moscow':'Russia'} print('原始列表的key顺序:',cities_dict) print("不对键排序时输出的city顺序:") for city in cities_dict.keys(): print(city + ' is the capital of ' + cities_dict[city] +'!') print("\n对键排序时输出的city顺序:") for city in sorted(cities_dict.keys()): print(city + ' is the capital of ' + cities_dict[city] +'!')
标签:实战,city,python,练习,dict,capital,print,cities From: https://www.cnblogs.com/bravesunforever/p/17627184.html