如何将单个或多个事物映射到 python 字典中的单个元素。
例如:
dict of str: {str: [str, int]}
myDict = dict()
myDict["myString"] = ["myList", 1, 0.0]
print myDict
输出
{'myString': ['myList', 1, 0.0]}
来自http://docs.python.org/2/library/stdtypes.html#mapping-types-dict的示例
您可以dict
通过以下方式在python中创建
>>> a = dict(one=1, two=2, three=3)
>>> b = {'one': 1, 'two': 2, 'three': 3}
>>> c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))
>>> d = dict([('two', 2), ('one', 1), ('three', 3)])
>>> e = dict({'three': 3, 'one': 1, 'two': 2})
>>> a == b == c == d == e
True
您可以使用列表代替任何值 ( 1, 2 or 3
)