How to Use the python dictionary for multi-key and repeated key values (detailed description), python dictionary
Use a dictionary in Python in the following format:
dict={ key1:value1 , key2;value2 ...}
The usage format for actually accessing dictionary values is as follows:
dict[key]
Multi-key value
The multi-key value format of the dictionary is as follows:
dict={(ke11,key12):value ,(key21,key22):value ...}
The specific format of actually accessing the value in the dictionary is as follows (take the first key as an example ):
dict[key11,key12]
Or:
dict[(key11,key12)]
The following is an example:
Multi-Value
When a key value corresponds to multiple values, the format is as follows:
dict={key1:(value1,value2 ..), key2:(value1,value2 ...) ...}
The format of the value in the access dictionary is as follows:
dict[key]
Or
dict[key][index]
Cyclic assignment (emphasis)
The syntax structure is shown in the following example:
Summary:
Through the preceding description, we can know that in the definition of the dictionary, the front and back of the colon (:) are a whole, that is, the front and back of the colon are included by parentheses, when accessing the dictionary value, it is best to put the key in parentheses as a whole.
Multiple key-value pairs with the same key value
That is, in the dictionary, there are at least two members with the same key, but the corresponding values of the key are different. The format is as follows:
dict={ key1: value1 key1: vaklue2, ... }
In this form, the value assigned to the key later becomes the real value of the key.
Use the list and dictionary as the dictionary Value
Format
dict={ key1:(key11:value,key12:value) , key2:(key21:value,key22:value) }
The format of the dictionary to be accessed (take the first key as an example ):
dict[key1][key11]
The actual example is as follows:
The above is all about how to use the multi-key and repeated key values of the python dictionary provided by xiaobian (detailed description). I hope you can support the help house ~