के रूप में अन्य जवाब कहा है, dict एक समारोह कॉल है: जबकि यह एक संख्या के साथ नामकरण इसे करने के लिए एक तर्क पारित कर दिया। इसमें तीन वाक्य रचनात्मक रूप हैं।
प्रपत्र:
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
कुंजी (या name
के रूप में इस मामले में इस्तेमाल किया) वैध अजगर identifiers होना चाहिए, और ints मान्य नहीं हैं।
>>> def f(**kw): pass
...
>>> f(one=1) # this is OK
>>> f(1=one) # this is not
File "<stdin>", line 1
SyntaxError: keyword can't be an expression
हालांकि, वहाँ आप के दो अन्य वाक्यात्मक रूपों का उपयोग कर सकते हैं:
सीमा न केवल समारोह dict
आप यह इतना तरह का प्रदर्शन कर सकते है।
है:
dict(iterable) -> new dictionary initialized as if via:
d = {}
for k, v in iterable:
d[k] = v
उदाहरण:
>>> dict([(1,'one'),(2,2)])
{1: 'one', 2: 2}
और एक मानचित्रण से:
dict(mapping) -> new dictionary initialized from a mapping object's
(key, value) pairs
उदाहरण:
>>> dict({1:'one',2:2})
{1: 'one', 2: 2}
,210
इतना (एक dict शाब्दिक से एक dict) की तरह लग सकता है जबकि नहीं ध्यान रखें कि Counter और defaultdict मैपिंग कर रहे हैं में रखने के लिए और यह कैसे आप एक dict के लिए उन में से एक भी बयान देगी:
>>> from collections import Counter
>>> Counter('aaaaabbbcdeffff')
Counter({'a': 5, 'f': 4, 'b': 3, 'c': 1, 'e': 1, 'd': 1})
>>> dict(Counter('aaaaabbbcdeffff'))
{'a': 5, 'c': 1, 'b': 3, 'e': 1, 'd': 1, 'f': 4}