Movatterモバイル変換


[0]ホーム

URL:


Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only.Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Filter Iterables With Python (Summary)

Python’sfilter() allows you to performfiltering operations on iterables. This kind of operation consists of applying aBoolean function to the items in an iterable and keeping only those values for which the function returns a true result. In general, you can usefilter() to process existing iterables and produce new iterables containing the values that you currently need.

In this video course, you learned how to:

  • Work with Python’sfilter()
  • Usefilter() toprocess iterables and keep the values you need
  • Combinefilter() withmap() andreduce() to approach different problems
  • Replacefilter() withlist comprehensions andgenerator expressions

With this new knowledge, you can now usefilter() in your code to give it afunctional style. You can also switch to a more Pythonic style and replacefilter() withlist comprehensions orgenerator expressions.

For further investigation, check out:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member?Sign-In

Locked learning resources

The full lesson is for members only.Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member?Sign-In

00:00Congratulations, you just aced this course!

00:05In this course, you understood the concept of filtering.You used thefilter() function to keep the things you need and filter out therest. You solved examples for both numbers and strings.

00:18You discovered themap() function and learned how you can use it to apply a functionto each element of an iterable and also discovered thereduce() functionand learned how you can combine elements of a sequence to produce a single result.

00:33Then you learned that by combiningreduce(),map(), andfilter(),you can achieve complex tasks with minimal code.

00:41You used thefilterfalse() function to keep elements that don’t meet the filteringcondition, unlike thefilter() function.And you also learned how to replacefilter() with list comprehensions andgenerators.

00:55If you’d like to learn more about Python iterators,lambda functions, and generator functions,check out these awesome Real Python courses and tutorials:Iterators and Iterables in Python, which is a written tutorial;How to Use Python Lambda Functions,which is both a video course and a written tutorial; and, as promised,How to Use Generators andyield in Python,which is both a video course and a written tutorial.

01:24This has been Negar with Real Python.Tell us what you think about this course and your favorite things that you’velearned in the comments. Stay awesome.

Avatar image for Marco Perez

Marco Perez onJuly 9, 2023

Very very cool.This demystified what was heretofore obscure and scary functions (filter, map, reduce) and syntax (lambdas).

Looking forward to using these lots!

Avatar image for Negar Vahid

Negar VahidRP Team onJuly 11, 2023

@Marco Perez I’m happy that filter, map, reduce and lambdas are not scary anymore! Hope you have fun using them in your future projects. Happy Pythoning!

Become a Member to join the conversation.

Course Contents

Overview
100%

[8]ページ先頭

©2009-2026 Movatter.jp