Python Filter Usage

Source: Internet
Author: User

1 class Filter (object) 2  |  or None, Iterable)-- Filter Object3  |  4  |   for which function (item) 5  |   is  is return The items that is true.

Filter reads all the items in the iterable, determines whether the keys are true for the function, and returns an iterator that contains all the items that are true. If function is None, returns a non-empty item.

1In [2]:ImportRe2In [3]: i = re.split (',',"123,,123213,,, 123213,")3in [4]: I4OUT[4]: ['123',"','123213',"',"','123213',"']

In this case, the list I contains an empty string.

1 Print (*filter (None, i)) 2 123 123213 123213

The filter then filters out the empty string in the list and gets an iterator containing only the non-empty string.

Print (List (filter (lambda x:x==', i))) [""]

Because Lambda is true to an empty string, filter filters out non-empty strings, leaving only empty strings.

Python Filter Usage

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.