About 5,060,000 results
Open links in new tab
  1. How can I filter items from a list in Python? - Stack Overflow

    Aug 22, 2009 · With and without list comprehensions: my_list = ['foo','bar','baz','>=','5.2'] # With only_words = [token for token in my_list if token.isalpha()] # Without only_words = filter(str.isalpha, my_list)

  2. How to Filter List Elements in Python By Practical Examples

    In this tutorial, you'll learn how to filter list elements by using the built-in Python filter() function.

  3. Filtering a list of strings based on contents - Stack Overflow

    Jan 28, 2010 · This simple filtering can be achieved in many ways with Python. The best approach is to use "list comprehensions" as follows: >>> lst = ['a', 'ab', 'abc', 'bac'] >>> [k for k in lst if 'ab' in k] ['ab', 'abc'] Another way is to use the filter function. In Python 2: >>> filter(lambda k: 'ab' in k, lst) ['ab', 'abc']

  4. Python's filter(): Extract Values From Iterables

    In Python, filter() is one of the tools you can use for functional programming. In this tutorial, you’ll learn how to: Use Python’s filter() in your code; Extract needed values from your iterables; Combine filter() with other functional tools; Replace filter() with more Pythonic tools

  5. Filter (extract/remove) items of a list with filter() in Python

    May 15, 2023 · In Python, you can use filter() to filter (extract/remove) items of a list, tuple, or other iterable that satisfy the conditions. Note that filter() can be substituted by list comprehensions or generator expressions, as described later, and in …

  6. How to Filter Lists in Python? - Python Guides

    Mar 3, 2025 · Learn how to filter lists in Python using list comprehension, `filter()`, and lambda functions. This step-by-step guide includes examples for easy understanding.

  7. 5 Ways of Filtering Python Lists - KDnuggets

    Nov 14, 2022 · 5 Ways of Filtering Python Lists. Filter the list elements using for loop, list comprehension, regex, filter(), and lambda functions.

  8. Python filter() Function: 5 Best Methods to Filter a List - FavTutor

    Nov 11, 2023 · Python provides a powerful built-in function called filter() that allows you to filter elements from a list, tuple, or any other iterable based on specific conditions. In this article, we will study various methods to filter a list in python using …

  9. How to Filter a List in Python [in 3 SIMPLE Ways] - codingem.com

    Today you are going to learn three ways to filter a list in Python. We start from a basic for loop approach. Then we use a list comprehension approach to make the code a bit more concise. Finally, we use the filter () function to make it even shorter.

  10. Filter List in Python - 3 Techniques - Python Examples

    To filter a list in Python, you can use For loop and if-statement, List Comprehension, or filter() built-in function. In this tutorial, we will go through these three ways to filter a list based on a condition or a function, with examples.