Functional Programming in Python: The 'filter()' Function

preview_player
Показать описание

In this Python tutorial you'll learn the basics of functional programming in Python and how to use the "filter()" function to transform data structures.

We'll take the example data set represented with an immutable data structure from the previous video in this series, and then we'll create a "filtered down" version of the same data using Python's built-in filter function. "filter()" is one of the functional programming primitives or building blocks available in Python and it's useful in a number of contexts.

Later in the video you'll also see how the filter function relates to list comprehensions and generator expressions in Python and how using these is (arguably) more Pythonic that relying on plain "filter()" calls.

This is part of a series of Python functional programming tutorials that I'm recording so stay tuned for the next instalment.

Also, be sure to check out these associated articles if you want to dive deeper into the subject:

* * *

FREE Python Coding Tutorials & News:
Рекомендации по теме
Комментарии
Автор

Best videos I’ve seen explaining the fundamentals of functional programming.

rileykilgore
Автор

This series is going really well. Keep up the good work, Dan!

fullone
Автор

Point out that producing lists through iteration costs memory tax at O(n+n) space. In smaller lists, you wouldn’t worry about it. Try doing that with larger lists, then you’ll see how things break. Generators have smaller memory footprint at O(n) by not creating a memory allocation for another list as you process the target list/tuple.

deanq
Автор

Thank you for explaining this in an understandable way! This helped me better understand both lambda functions and the filter function.

joshuagardner
Автор

Thank you for the great tutorial. I really appreciated and your clarification of "is True" being implied, and then leaving it in the code to better clarify what is happening.

BradAtherton
Автор

Code is written to be read by other programmers.
It also happens to run on machines.
Being able to understand code quickly and reason about it is maximally important.
Leave it to the compiler (or the interpreter here) to find the fastest way to do the "i want you to filter this" dance.
Tell the fellow programmer what you want to be done, not how the program should do it.

seven
Автор

what is the correct term for getting the data from an iterator - "materialise"??

TheWorpler
Автор

Really nice tutorials, I have been experimenting a lot with functional programming (I highly recommend Elixir) and I think that the most important thing when you look at the code you are seeing terms, propositions and affirmations instead of the steps to solve a problem.
Declarative programming style is the future! <3

alvarorc
Автор

Appreciate the functional programming series! thanks!

BrendanMetcalfe
Автор

What software do you use to run python on because that does not look like vscode

adlifiruz
Автор

Bought Python Tricks book today! Learning was never this fun. Thanks so much Dan for inspiring and teaching us.

udaybhagwat
Автор

Dan, would be great if you could do a video on decorators, why we use them, a senario where you can show case the usage of decorator and what happens if you don't use them. Great videos. Thank you again for all the efforts. Super helpful.

DARIUSHAZIMI
Автор

Simple and effective tutorial. Thank you :)

mkumarsd
Автор

Well mapped out delivery of content (no pun intended) and yes, I do now better understand listcomps and genexp. Thanks

charliec
Автор

For booleans 'x' is preferable to 'x is True' according to pep8 (see the bottom of the "Programming Recommendations" section)

IgnatShining
Автор

Composing these would've been soooo much easier if python had extension methods. C#, of all languages, seems more 'pythonic' in this regard.

biskitpagla
Автор

Great video. Hoping that you will get into more complex uses of build-in functions like filter or even itertools.

ivenhoe
Автор

Except it doesnt matter if you do tuple of list of pyobject or tuple of pyobject as the JIT compiler optimises it anyway and doesnt create an intermediate list

GameSmilexD
Автор

Hi Dan, Thanks for posting these videos. They really help me to learn python. How can I Replace Strings based on column number in CSV? I mean if the value is 0 in column 2 i need to replace it with null?

yoco
Автор

I used "lambda x: x.nobel" instead of your "lambda x: x.nobel is True".

jaysanprogramming
join shbcf.ru