Python filter List Usage example analysis

Source: Internet
Author: User
This example describes the Python filter list usage. Share to everyone for your reference, as follows:

Filter List

[Mapping-expression for element in Source-list if filter-expression]

The filter expression, which starts with an if, is any expression that returns a value of True or false (almost anything in Python). Any filter expression calculus value for an element can be included in the map. Other elements are ignored, they do not enter the mapping expression, and are not included in the output list.

>>> li = ["A", "Mpilgrim", "foo", "B", "C", "B", "D", "D"]>>> [Elem for Elem in Li if Len (elem) > 1][ ' Mpilgrim ', ' foo ']>>> [Elem+elem for Elem in Li if Len (elem) > 1][' Mpilgrimmpilgrim ', ' Foofoo ']>>>

Read more about Python topics: python Regular expression Usage summary, Python data structure and algorithm tutorials, Python socket Programming Tips Summary, Python function Usage tips summary, "How-to" Python string manipulation Tips Summary, Python Introductory and Advanced classic tutorials, and Python file and directory operations tips

I hope this article is helpful for Python program design.

  • Related Article

    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.