Python Filter list usage instance analysis, python usage instance analysis
This example describes how to use Python to filter lists. We will share this with you for your reference. The details are as follows:
Filter list
[Mapping-expression for element in source-list if filter-expression]
A filter expression starts with if. A filter expression can be any expression that returns a true or false value (almost anything in Python. Any truth that is calculated as an element by a filter expression can be included in the ing. Other elements will be ignored, and they will not enter the ing expression, nor be 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] ['mpilgrimmilgrim', 'foofoo'] >>>