如何在Python中组织地图

时间:2016-06-06 18:12:43

标签: python

我是python的新手,我刚开始学习语法。我想创建一个映射(就像在java中,但我知道它们可能在python中被称为其他东西)所以我认为代码可能看起来像这样

map = {}
map.append("somestring": 12)
map.append("anotherstring": 10)
map.append("yetanotherstring": 15)
'''
then organize the map by the numbers from largest to smallest
so if I were to then run through the map with a for loop it would
print 
"yetanotherString" : 15
"somestring" : 12
"anotherstring" : 10
'''

我无能为力在这个过程的几乎每一步中,宣布一个" map"通过整理来组织它。虽然通过整理来组织它是我最大的问题。

1 个答案:

答案 0 :(得分:1)

他们称之为词典

试试这样:

pythonDict = {}

pythonDict['somestring'] = 12

http://learnpythonthehardway.org/book/ex39.html

中查看详情

要了解有关迭代字典的详情,请参阅https://docs.python.org/2/library/itertools.html

相关问题