Python iterator list parser

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.