python list of dictionaries comparing the set of tuples

 

definition method
List Can contain different types of objects, the element can be increased or decreased, may be combined with other list or a list of the split, with [] EG defined: aList = [123, 'abc', 4.56, [ 'inner', ' list '], 7-9j] 1.list (str): to convert into a list type str, str string can be a tuple type 2.aList.append ( 'test'): is added to the list of elements to 3.del aList [1]: deleted from the list of elements the subscript 1 del aList: delete the entire list 4.cmp ​​(list1, list2): compare the two lists size 5.len (list): returns the number of list element 6.sorted (list): using lexicographically sorting elements in the list 7.reversed (list): the inverted position of the element 8.list.count (obj) list: returns the object obj number appears in the list 9.list.extend (seq): the sequence seq content added to the list 10.list.insert (index, obj): the amount of the index index is inserted in place of the object obj 11.list.pop (index = -1): delete the specified position and returns the object, default the last object 12.list.remove (obj): Object obj deleted from the list
Tuple It can contain different types of objects, but are immutable and can not increase or decrease in the elements, using () to define eg: aTuple = (123, 'abc', 4.56, [ 'inner', 'list'], 7- 9j) 1.tuple (obj): to convert into a tuple object obj objects, obj can be any string or a list of list (2) for del, cmp, len, max, min tuple method is also applicable to, but because tuples are immutable , substitutions, additions, sorting can not be achieved
dictionary Key-value pairs defined by {} eg: aDict = { 'name': 'cynthia', 'age': 18}

. 1.dict1 = dict (([ 'x', 1], [ 'y', 2])): dict () create a dictionary 2.dict1 = {} fromkeys (( 'x', 'y'), - 1): fromkeys () creates a default dictionary, the dictionary elements have the same value 3.dict1.keys (): Get a list of keys of the dictionary 4.dict1.has_key ( 'x'): determines whether the dictionary 'x 'key, return bool type 5.dict.get (key, default): returns the value of the key-key, if the key does not exist, the return value 6.dict.items default (): returns a list of key-value pair 7. dict.values ​​(): returns the dictionary list 8.dict.update (dict2) all values: the dict2 list of key-value pairs added to the dictionary dict go 9.dict.pop (key): returns the value of the key key 10.setdefault (): get a similar method, it is possible to obtain a given value of the key, in addition also in auto setdefault containing no case is set to a given key corresponding key-value 11.clear (): Clear all dictionary items. Place operations, no return (return value or said None) 12.copy (): returns the new dictionary with the same key-value as a pale copy (shallow copy)

set

set () variable set

frozenset () set immutable

Method (set of all methods):
s.issubset (t) if s is a subset of t returns True, otherwise return False
s.issuperset (t) s is a superset if t returns True, otherwise it returns False
s. Union (t) returns a new collection, which is set and s and t
s.intersection (t) returns a new collection, which is the intersection of s and t
s.difference (t) returns a new collection that s is a member, but not a member of t, that is an element other than t s return of
s.symmetric_defference (t) s and t return all proprietary (non co-owner) collection of elements
s.copy () returns a shallow s copy, the efficiency is better than the factory

method (only for set variable): the following method parameters must be hashed
s.update (t): s t-modify the elements, i.e., s now contains s or t member
s .intersection_update (t): s is a member of the common elements belonging s and t
s.difference_update (t): s is a member of an element belonging to t s, but not included in the
s.symmetric_difference_update (t): s in members to update those contained in s or t but not the elements common to s and t
s.add (obj): add an object obj in the set s in
s.re move (obj): Object obj deleted from the set s, if s the elements (obj not in s) obj is not a collection, will lead to keyError error
s.discard (obj): If obj is a collection of elements in s, from the collection s To remove an object obj
s.pop (): Delete the set s to give any object, and returns it
s.clear (): Delete all elements in the set s

Guess you like

Origin www.cnblogs.com/aibabel/p/11030887.html