Review:
1. Dynamic language
The number of times the Sys.getrefcount () object was referenced.
Scenarios for increasing the number of object references: Creating an object as an assignment, when the object is an element of a container, being passed as a parameter to a function, and creating another variable name for the object;
Reduced reference count: A variable name referencing this object is explicitly destroyed by the Del X, re-assigned to the variable name referencing the object, removing the object from the container, List.pop (), and the container itself being destroyed;
Complete and non-complete traversal
Python iterator
Also called the cursor, is the programming software design pattern, is one kind can implement the element traversal on the container object the interface. is a special kind of data structure, and in Python, it also exists as an object.
Iterable can iterate objects: objects implement the __iter__ method, some user-defined classes that contain __iter__ () or __getitem__ methods, sequence types list, str, tuple. Support for non-sequential type Dict,file returns one member object that it contains each time.
Calling the __iter__ method creates an iterator in memory that iterates through its elements through the next method until the end of the traversal. No more starting from scratch.
The ITER () function enables the production of an iterator.
Iterators are objects that follow an iterative protocol, which is passed through an iterative protocol to the ITER () built-in function, allowing an iterator to be obtained from an iterative object that contains the required next () method.
List parsing: An application of the iterative mechanism. Used to implement a new list efficiently based on an existing list.
[Expression for Iter_var in Iterable (an iterator object)]
L2 = [I * * 2 for I in L1]
[Expression for Iter_var in Iterable if COND_EXPR] to determine the element that meets the criteria by the IF
Python iterator list parser