#字典
Dict,dict Full Name dictionary, also known as map in other languages, is stored using key-value (Key-value) and has a very fast lookup speed.
Dict key (value) contains list and Tuple,key immutable, key can be tuple (tuple cannot become list, list variable)
>>> B = {"A": 1, "B": "Sad", "C":(1,["DSSD"])}>>> b{' A ': 1, ' B ': ' Sad ', ' C ': (1, [' DSSD '])}>>> Typ E (b) <class ' dict ' >
#set
Set is similar to Dict and is a set of keys, but does not store value. In set, there is no duplicate key. When creating a set, you need to provide a list as the input collection:
The set type is stored as key, so the type can be joined Tuple,list, the write type is ([]), and the output is a collection.
>>> A=set ([i]) >>> a{1, 2, 3}>>> type (a) <class ' dict ' >
#例子:
To put (1,[2,3]) into a dict or set.
>>> a= (all in All) >>> type (a) <class ' Tuple ' >>>> b= (1,[2,3]) >>> type (b) <class ' tuple ' >>>> c= {"W": 1, "G": 2}>>> d=set ([i]) >>> type (c) <class ' Dict ' >>>> type (d) <class ' Set ' >>>> c["a"]=a>>> a (1, 2, 3) >> > c{' W ': 1, ' G ': 2, ' a ': (1, 2, 3), ' B ': (1,&NBSP;2, &NBSP;3)}>>> c["B"]=b{' W ': 1, ' G ': 2, ' a ': (1, 2, 3), ' b ': (1, [2, 3])}>>> d.add (a) >>> d{1, 2, 3, (1, 2 , 3)}>>> d.add (b) traceback (most recent call last): File "<stdin>", line 1, in <module>typeerror: unhashable type: ' list '
This article is from the "Twist Blog" blog, please be sure to keep this source http://mahua.blog.51cto.com/11572858/1969209
(record) Beginner Python article: five