Difference python lists, tuples, dictionaries, dictionaries

First, a list of

1. ordered set of arbitrary objects 
list is a set value of any type, combination in a certain order 2. By reading the offset , called elements (Elements) consisting of a list of values. Each element is identified an index, the first index is 0, the function can be realized sequence 3. The variable length, isomers and any nested list elements can be of any type, or even a list type, that is to say lists can be nested 4. the variable sequences support indexing, slicing, merge, delete, etc. operations that are carried out in situ modification list 5. the array of object references list can be used as ordinary array, whenever a reference is used, Python this will always be a reference to an object, so the program simply processing operation objects. When the object is assigned to a data structure element or a variable name, Python always stores a reference to the object, rather than a copy of the object 
 
 
 
 
 
 
 

 

Second, the tuple

1. arbitrary ordered set of objects 
of the same list 2. By offsetting access the same list 3. an immutable type sequence modified at any of the original strings similar to list, but the tuples are immutable, it does not support operation, does not support any method calls 4. the fixed length, heterogeneous, arbitrarily nested fixed length i.e. tuples immutable, fixed length without being copied, the other with a list of the array of 5 object references a list similar to the ancestral It is an array of object references 
 
 
 
 
 
 
 

And comparison list 
1. List faster than the operating speed 2. Data "write protection" 3 may be used to string formatting key 4. dictionary as 
 
 

 

Third, Dictionary

1. not be read by the key offset 
dictionary is an associative array, an object is set by the keyword index using the key - the value (key-value) stores, fast search speed 2. arbitrary objects without ordered set item dictionary in no particular order, a "key" as a symbol 3. a variable length, isomers, any nested with the list may contain a list of nested dictionaries, and other 4. mapping type is variable because it is disorder, sequence of operations can not be performed, but can be modified in the distance, through the key mapped to a value. Only the built-in dictionary mapping types (objects that map to the key value) The object reference table dictionary storage object reference is not copied, and the same list. The key is the dictionary can not change, list can not be used as key, string, ancestral, and so can be an integer 
 
 
 
 
 
 
 

Compare and list, dict has the following characteristics: 
1. Locate and insert fast, will not increase key increases 2. take a lot of memory, more than a waste of memory while the opposite list: 1. Find and insert the time element increases with the increase of 2 small footprint, waste very little memory so, dict is a way to trade off space for time 
 
 
 
 

 

Fourth, the collection

1 is a set of key, but not stored value, and the key can not be repeated 
to create a set, need to provide a list as a set of inputs, s = set ([1,2,3] ), note that the incoming parameters [ 1, 2, 3] is a list, and set display ([1, 2, 3]) just tells you the internal set 1,2,3 these three elements, display [] indicates that this is not a list 2. repeat the filter elements in the set are automatically set and can be seen as non-repeating unordered collection of elements in the mathematical sense, therefore, the intersection of two set can be done in the mathematical sense, and set operations such as 
 

There is also a collection is forzenset (), is a collection of frozen, it is immutable, there is a hash value, the benefit is that it can be used as a dictionary key can also be used as other elements of the collection. The disadvantage is that once created can not be changed, not add, remove method

Comparative dict and 
the only difference is that only dict 1.set and does not store the value corresponding to the same principle and 2.set dict, not into the same variable object, because the object can not be determined whether the variable is equal to two, it can not ensure that the internal set "there will be no repeat element" 

First, a list of

1. ordered set of arbitrary objects 
list is a set value of any type, combination in a certain order 2. By reading the offset , called elements (Elements) consisting of a list of values. Each element is identified an index, the first index is 0, the function can be realized sequence 3. The variable length, isomers and any nested list elements can be of any type, or even a list type, that is to say lists can be nested 4. the variable sequences support indexing, slicing, merge, delete, etc. operations that are carried out in situ modification list 5. the array of object references list can be used as ordinary array, whenever a reference is used, Python this will always be a reference to an object, so the program simply processing operation objects. When the object is assigned to a data structure element or a variable name, Python always stores a reference to the object, rather than a copy of the object 
 
 
 
 
 
 
 

 

Second, the tuple

1. arbitrary ordered set of objects 
of the same list 2. By offsetting access the same list 3. an immutable type sequence modified at any of the original strings similar to list, but the tuples are immutable, it does not support operation, does not support any method calls 4. the fixed length, heterogeneous, arbitrarily nested fixed length i.e. tuples immutable, fixed length without being copied, the other with a list of the array of 5 object references a list similar to the ancestral It is an array of object references 
 
 
 
 
 
 
 

And comparison list 
1. List faster than the operating speed 2. Data "write protection" 3 may be used to string formatting key 4. dictionary as 
 
 

 

Third, Dictionary

1. not be read by the key offset 
dictionary is an associative array, an object is set by the keyword index using the key - the value (key-value) stores, fast search speed 2. arbitrary objects without ordered set item dictionary in no particular order, a "key" as a symbol 3. a variable length, isomers, any nested with the list may contain a list of nested dictionaries, and other 4. mapping type is variable because it is disorder, sequence of operations can not be performed, but can be modified in the distance, through the key mapped to a value. Only the built-in dictionary mapping types (objects that map to the key value) The object reference table dictionary storage object reference is not copied, and the same list. The key is the dictionary can not change, list can not be used as key, string, ancestral, and so can be an integer 
 
 
 
 
 
 
 

Compare and list, dict has the following characteristics: 
1. Locate and insert fast, will not increase key increases 2. take a lot of memory, more than a waste of memory while the opposite list: 1. Find and insert the time element increases with the increase of 2 small footprint, waste very little memory so, dict is a way to trade off space for time 
 
 
 
 

 

Fourth, the collection

1 is a set of key, but not stored value, and the key can not be repeated 
to create a set, need to provide a list as a set of inputs, s = set ([1,2,3] ), note that the incoming parameters [ 1, 2, 3] is a list, and set display ([1, 2, 3]) just tells you the internal set 1,2,3 these three elements, display [] indicates that this is not a list 2. repeat the filter elements in the set are automatically set and can be seen as non-repeating unordered collection of elements in the mathematical sense, therefore, the intersection of two set can be done in the mathematical sense, and set operations such as 
 

There is also a collection is forzenset (), is a collection of frozen, it is immutable, there is a hash value, the benefit is that it can be used as a dictionary key can also be used as other elements of the collection. The disadvantage is that once created can not be changed, not add, remove method

Comparative dict and 
the only difference is that only dict 1.set and does not store the value corresponding to the same principle and 2.set dict, not into the same variable object, because the object can not be determined whether the variable is equal to two, it can not ensure that the internal set "there will be no repeat element" 

1. ordered set of arbitrary objects 
list is a set value of any type, combination in a certain order 2. By reading the offset , called elements (Elements) consisting of a list of values. Each element is identified an index, the first index is 0, the function can be realized sequence 3. The variable length, isomers and any nested list elements can be of any type, or even a list type, that is to say lists can be nested 4. the variable sequences support indexing, slicing, merge, delete, etc. operations that are carried out in situ modification list 5. the array of object references list can be used as ordinary array, whenever a reference is used, Python this will always be a reference to an object, so the program simply processing operation objects. When the object is assigned to a data structure element or a variable name, Python always stores a reference to the object, rather than a copy of the object 
 
 
 
 
 
 
 

 

Second, the tuple

1. arbitrary ordered set of objects 
of the same list 2. By offsetting access the same list 3. an immutable type sequence modified at any of the original strings similar to list, but the tuples are immutable, it does not support operation, does not support any method calls 4. the fixed length, heterogeneous, arbitrarily nested fixed length i.e. tuples immutable, fixed length without being copied, the other with a list of the array of 5 object references a list similar to the ancestral It is an array of object references 
 
 
 
 
 
 
 

And comparison list 
1. List faster than the operating speed 2. Data "write protection" 3 may be used to string formatting key 4. dictionary as 
 
 

 

Third, Dictionary

1. not be read by the key offset 
dictionary is an associative array, an object is set by the keyword index using the key - the value (key-value) stores, fast search speed 2. arbitrary objects without ordered set item dictionary in no particular order, a "key" as a symbol 3. a variable length, isomers, any nested with the list may contain a list of nested dictionaries, and other 4. mapping type is variable because it is disorder, sequence of operations can not be performed, but can be modified in the distance, through the key mapped to a value. Only the built-in dictionary mapping types (objects that map to the key value) The object reference table dictionary storage object reference is not copied, and the same list. The key is the dictionary can not change, list can not be used as key, string, ancestral, and so can be an integer 
 
 
 
 
 
 
 

Compare and list, dict has the following characteristics: 
1. Locate and insert fast, will not increase key increases 2. take a lot of memory, more than a waste of memory while the opposite list: 1. Find and insert the time element increases with the increase of 2 small footprint, waste very little memory so, dict is a way to trade off space for time 
 
 
 
 

 

Fourth, the collection

1 is a set of key, but not stored value, and the key can not be repeated 
to create a set, need to provide a list as a set of inputs, s = set ([1,2,3] ), note that the incoming parameters [ 1, 2, 3] is a list, and set display ([1, 2, 3]) just tells you the internal set 1,2,3 these three elements, display [] indicates that this is not a list 2. repeat the filter elements in the set are automatically set and can be seen as non-repeating unordered collection of elements in the mathematical sense, therefore, the intersection of two set can be done in the mathematical sense, and set operations such as 
 

There is also a collection is forzenset (), is a collection of frozen, it is immutable, there is a hash value, the benefit is that it can be used as a dictionary key can also be used as other elements of the collection. The disadvantage is that once created can not be changed, not add, remove method

Comparative dict and 
the only difference is that only dict 1.set and does not store the value corresponding to the same principle and 2.set dict, not into the same variable object, because the object can not be determined whether the variable is equal to two, it can not ensure that the internal set "there will be no repeat element" 

Guess you like

Origin www.cnblogs.com/vvsq/p/11351436.html