python ---- four built-in data structures (dict, list, tuple, set)

1、dict

  Disorderly, you can change

2、tuple

  Orderly, can not be changed

3、list

  Orderly, you can change (add, delete)

4、set

  Disorder, may change

  {Element 1, element 2, element 3 .....} as dictionaries and braces are defined, but none except that colon-separated, there is a method is defined () function is passed an arbitrary sequence to a set (e.g., a string set ( 'fsdaf'))

2 sets of operations:

  python is set in the mathematical set of contract also has to pay, and, poor operation and which provides a method of calculation Union (), a difference method set difference () but here the difference is only Display Set is different from the method used the method of all the elements of another set, the intersection of the intersection () show the same elements

The following code is used to implement the method described above:

# Operation set 
TEMP = { ' A ' , ' E ' , ' I ' , ' O ' , ' U ' } 
temp2 of = SET ( " FDA " ); 

# intersection operation 
Result = TEMP. Intersection (temp2 of) # { ' A '} 

# and operation 
result = temp. Union (temp2 of) # {' A ',' O ',' F ',' D ',' U ',' E ',' I '} 

# difference operation 
result = temp .difference(temp2)#{ 'A', 'e', ​​'u', 'i'}

 

Guess you like

Origin www.cnblogs.com/syw20170419/p/10986059.html