7. The container data type set_dict

# ### and container type data set dict 
 
# collection set ### (set up and used for the operation of the cross) 
'' 'to automatically re-disordered' '' 
# (1) defines an empty set 
setvar = set ( ) # {} is not set but a dictionary 
Print (setvar, type (setvar)) 
 
# (2) automatically to a weight disorder 
setvar = { "Jay", "Baoqiang", "Li"} 
Print (setvar) 
setvar = { "Andy", "Cheung", "Aaron", "Wang", "Wang"} 
Print (setvar) 
 
# (. 3) neither acquired nor modified 
# RES = setvar [0] 
 
 
 
 
# ### dict dictionary 
" "" 
# on the dictionary 
prior to version 3.6 dictionary disorder, 
after the 3.6 version, the dictionary order (order appears essentially random) 
 
hash algorithm: 
    arbitrary length immutable values calculated as having a fixed length the only value, 
    this value can be positive or negative, large or small, calculated by the key, to get the value, the effect of forming one mapping of 
    pipe algorithm called a hash algorithm, this value is called the hash value of the 
     
    dictionary storage time ,The order is not necessarily literally stored in memory 
    but by hash algorithm, a hash of the random key corresponding to the value stored in memory, so the dictionary disorder (for the sake of efficiency, FIG fast)
    Can be calculated by obtaining a hash key by the hash value 
# dictionary to change the value of the key by
     
    After 3.6 recorded dictionary literal sequence, when fetched, are reordered, so it looks like an ordered (but essentially random, as long as he uses hash) 
     
    may be hashed data (immutable data): Number (int float complex bool) str tuple 
    is not hashed data (variable data): list set dict (list dict value of the variable; variable set order) 
     
    value of the set of keys need be hashed dictionary data, the remaining data do not care. 
"" " 
'' 'by the key data composed of an ordered' '' 
# define an empty dictionary 
dictvar} = { 
Print (dictvar, type (dictvar)) 
 
'' ' 
# syntax: 
dictvar = {' a ': 1} 
# "key": "value" between the key and value separated by a colon, key-value pairs separated by commas 
' '' 
dictvar = { "Top": "Yaojin", "Middle" : "Enchantress", "bottom": "Cui Si Tana", "jungle": "seven loud", "support": "Demacian"} 
Print (dictvar,(dictvar)) type 
 
# Gets the value of the dictionary from among the (value acquired by the key) 
RES = dictvar [ 'Middle'] 
Print (RES) 
 
dictvar [ 'Top'] = "Zhao letter" 
Print (dictvar)
 
# Hashable data (dictionary) is not recommended to use the following key string variable named general to use to define the key 
dictvar = {35: 1,36: True , 3.15: "111", False: "112233", 3 + 2j: 12, "big guy": 78, (11,22,333):}. 4 
Print (dictvar) 
# acquired. 4 
Print (dictvar [(11,22,333)]) 
dictvar [False] = 67 
Print (dictvar) 
 
# can Ha data Xi (set) 
# setvar = {l, 2,3, [4,5,6]} 
# Print (setvar) 
 
# unique dictionary if the preceding two identical keys behind the cover 
# dictionary key is not unique modify the value of the dictionary random 
dictvar = { "a":. 1, 'a': 2} 
Print (dictvar)

  

Guess you like

Origin www.cnblogs.com/eliwen/p/10967658.html