Python dictionary key mapping in a plurality of values (or a list set)

 

A dictionary is a map corresponding to a single key value.

If you want a key mapping multiple values, then you need these multiple values into another container, such as a list or collection inside. This dictionary can be constructed like the following:

 

= {the Message ' Name ' : ' Ma ' , ' gender ' : ' male ' , ' Age ' : 18 } 

# with a list of 
the Message [ ' hobby ' ] = [ ' for the money are not interested ' , ' spend interested ' ]
 # In set 
Message [ ' interest ' ] = { ' do not want to start Ali ' , ' boring ' }
Choose to use depends on your list or collection of actual demand. If you want to keep the element insertion order you should use a list, if you want to remove duplicate elements on the use of the collection (and do not care about the order of the elements of the problem).
{ ' Name ' : ' Ma ' , ' gender ' : ' male ' , ' Age ' : 18, ' hobby ' : [ ' for the money are not interested ' , ' spend interested ' ], ' interest ' : { ' boring ' , ' do not want to venture Ali ' }}

Guess you like

Origin www.cnblogs.com/qzyhome/p/11410019.html