P55 string

2019-09-19 
07:45:33

# 1.Dictionary Dictionary
'' '
dictionary python is the only type of map using stored key-value pairs of data (key-value) of. python hash function operation on the key determines the memory address value according to the result of the calculation, the dictionary is stored unordered, and the key must be hashed.
It may represent the hash key must be immutable type, such as: a number, a string, a tuple. Dictionary (dictionary) is among the list of the most unexpected python flexible built-in data types other structures.
Is an ordered list of target binding, dictionaries are unordered collections of objects. The difference between the two is that: among the elements of the dictionary is accessed by a key, rather than by shifting access.
'' '
#! ! Dictionary change by same check can be deleted with del
# dictionary. 1 is in brackets, and the content of the disorder, i.e., without the following table.
DIC1 = { 'name': 'Alex', 'Age': 36, 'Sex' : 'MALE', 'dd': True}
to the #NAME a bond, Alex value, the key is a unique, non-variable, only a mapping relationship, such as phonetic dictionary, the search word phonetic S led to find the same key S point value

. immutable type # 2: plastic, string, a tuple of variable types: a list of dictionary (type variable value, just as immutable keys)
DIC2 = { 'Sex': 'M', 'number ': '10', 'ip' : '5201314'} # is Sex (key) is immutable, the "male"



# 3 anyway dic = { "immutable": "Variable Type"}
# plastic, string, a list of tuples, dictionaries

# 4 it is disordered.
# Hypothesis subscript: 1,2,3, 4,5,6
dic3 = { 'sex_1': 'M', 'number_1': '10 ', 'ip_1': '5201314', 'love': ' woman', 'home': '301 ', 'want ':' Rich ',' ABC ':' 456 ',' Zoo ':' dd '}
Print (dic3) # because it is disordered, it is possible to

# 5 can be built-in dictionary dictionary.
# because the value of variable type, and the dictionary is, the dictionary can be built-in dictionary
dic4 = { 'sex': 'M', 'Number': '10', 'IP': { 'BY': 'C'}}
Print (DIC4 [ ' ip '])

# create a dictionary
dic11 = dict (((' name ',' alex '),)) # Another way to create the dictionary
Print (DIC1)
Print (DIC2)

# increase
dic3 = {}

dic3 [ 'name'] = 'Alex'
dic3 [ 'Age'] = 18 is
Print (dic3) # { 'name ':' Alex ',' Age ':} 18 is

A = dic3.setdefault (' name ',' Yuan ')
b = dic3.setdefault ( 'ages', 22) # Another method of increasing the dictionary
Print (A, B)
Print (dic3)

# check
dic3 = { 'name': 'Alex', 'Age':} 18 is
Print (dic3.items ()) #items () function to return may traverse the list (key, value) tuples array.
print (dic3.keys ()) #keys ( ) function returns a list of tuples can be key array traversal.
print (dic3.values ()) #valuss ( ) function returns the value to the list of tuples can traverse the array.

print ( 'name' in dic3) # dic3 determines if the name is True where otherwise False
Print (List (dic3.values ()))

# change
dic3 = { 'name': ' alex', 'age': 18}
dic3 [ 'name'] = 'Alvin'
DIC4 = { 'Sex': 'MALE', 'Hobby': 'Girl', 'Age': 36}
dic3.update (DIC4) #.
print (dic3, dic4) # >>> { 'name': 'alvin', 'age': 36, 'sex': 'male', 'hobby': 'girl'} { 'sex': 'male', 'Hobby': 'Girl', 'Age': 36}


# deleted
DIC4 = { 'name': 'Alex', 'class':. 1, 'Age': 18 is,}

del DIC4 [ 'name'] # normal deleted , no return value {>>> 'class':. 1, 'Age':} 18 is
Print (DIC4)

B = dic4.pop ( 'Age') #pop delete, return values >>> 18 { 'class': }. 1
Print (B, DIC4)

A = dic4.popitem () # randomly delete, return values >>> ( 'class',. 1)} {
Print (A, DIC4)

dic4.clear () # empty dictionary >> >} {
Print (DIC4)

# Other operations and methods according to

# .fromkeys () function creates a new dictionary, the sequence elements do abc dictionary key, all keys corresponding to the CDE as a dictionary initial value. Dic041.fromkeys ( [ 'abc', 'abc' ], cde)! need a dictionary
SEQ = {}
dict = seq.fromkeys ([ 'ABC', 'ABCD'], 'Love')
Print (dict) >>> # { 'ABC': 'Love', 'ABCD': 'Love'}

# .copy () function to return a shallow copy of dictionary
dict44 = { 'Name': ' Runoob', 'Age ':. 7,' Class': 'First'}
dict22 = dict44.copy ()
Print ( "new dictionary is copied:", dict22) # >>> new dictionary is copied: { 'Name': 'Runoob ' , 'Age':. 7, 'Class': 'First'}

#sorted iterations for all objects can be sorted sorting operation method returns a new list, rather than operation performed on the basis of the original. Returns a value to all objects
#sort method returns a list of the existing operation, no return value applies only listing
dic0415 = {. 5: '555', 2: '222',. 3: '333'}
Print (sorted (dic0415)) # default key arrangement >>> [2,. 3,. 5]
Print (the sorted (dic0415.

print (sorted (dic0415.values ()) ) # arrangement value >>> [ '222', '333', '555']

# 1 dictionary traversal
dic5 = { 'name': ' alex', 'age': } 18 is

for I in dic5:
Print (I, dic5 [I]) # optimal fast

for items in dic5.items ():
Print (items)
for Keys, dic5.items values in ():
Print (Keys, values )

# list of nested
av_catalog = {
"Europe": {
"www.youporn.com": [ "a lot of free, the world's largest", "quality in general"],
"www.pornhub.com": [ "a lot free, but also great "," quality than yourporn high point "],
" letmedothistoyou.com ": [" mostly selfie, a lot of high-quality images, "" limited resources, updates slow "],
" the X--Art. com ": [" high quality,Really high, "" all the charges, please bypass ratio Cock "]
},
" South Korea ": {
" tokyo-Hot ": [" Quality is not clear how the individual is no longer like Japan and South Korea Fan "and" listen said that the charges "]
},
"Mainland": {
"1024": [ "all free, good, good life of peace", "server in a foreign country, slow"]
}
}

av_catalog [ "continent"] [ "1024"] [1] + = " reptile can climb down "# modify, or add a list of
print (av_catalog [" continent "] [" 1024 "])

Guess you like

Origin www.cnblogs.com/Black-sail/p/11546634.html