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.