如何在python中将单个或多个事物映射到字典中的单个元素。
例如:
dict of str: {str: [str, int]}
答案 0 :(得分:1)
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
的示例您可以通过以下方式在python中创建dict
>>> 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
)