Search notes:

Python: filter

filter can be used to extract elements from a list that meet a certain condition. It's probably the closest equivalent to Perl's grep function.

Filter in combination with a lambda function

The following snippet uses a lambda expression to filter the numbers whose length is less or equal to four characters:
#!/usr/bin/python

nums  = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']

#
#  Use a lambda function to filter the numbers whose length
#  is less or equal to four characters:
#
nums_ = filter(lambda L: len(L) <= 4, nums)

for num in nums_:
    print(num)
Github repository about-Python, path: /builtin-functions/filter/lambda.py

See also

filter(…) is different from list comprehension in that filter(…) returns an iterator (a filter object) while the list comprehension returns a list.
Python: Built in functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1738303043, '3.15.192.146', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/built-in-functions/filter(60): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78