Python's Filter Function Explained..

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

Background Music:
Creative Commons / Attribution 3.0 Unported License (CC BY 3.0)
Рекомендации по теме
Комментарии
Автор

Don't forget lambdas! We don't always need to define a function if we're checking something more simple.

We can also return the result of the IF check rather than writing out a full IF/ELSE clause: `return x < 1600 and y >= 2` will return True or False itself.

SmashPortal
Автор

I know it's a video just about the filter function, but you could add a "list comprehension" for this example in this video to show a more professional and cooler alternative to the filter function. Then it will be easier to understand the logic of one and the other method, simple 2 in 1. 1 line of code vs 9 😁

x = [key for (key, value) in avail_units.items() if value["price"] < 1600 and value["bedrooms"] >= 2]

krzysiekkrzysiek
Автор

Cool videos! How do you get such a clean terminal in vs code?

tonisvalk
Автор

There are two quite important uses with the filter function that you didnt mention:

1. You can use a lambda inside the function: "filter(lambda x: x % 2 == 0, range(10))"
2. You can use None as a special function to create a type safe non-null collection invariant. Say you have a list (values) of None or integers (list[None | int]) and you only want the list of integers you can use "filter(None, values)" to get a "Iterable[int]" type. which only contains the integers from the list.

Additionally you can also create filters that are easier to read using the comprehension syntax:
values = (num for num in numbers if num % 2 == 0)

cn-ml
Автор

Please dont use
if condition:
return true
else:
return false
just use return condition 😭😭

Terra_
Автор

1:55 Why not just return the bool directly?

OneWeirdDude
Автор

Returning True from an if and False from an else is the same as returning the condition. I prefer the second way because it's simpler. ¿Which do you choose and why?

starklosch
Автор

sometimes you learn something because you tried to name something the wrong thing (in hindsight, my list should have been called "mask" instead of "filter") and have to google it when the IDE changes your text color.

EDoyl
Автор

is the avail_units a dictionary of dictionaries ? I think I got a little confused when I saw the extension.

foralx
Автор

Why not just set the function to return a list with the value meeting the criteria and be done with it?

The filter step seems unnecessary

fanoflinoa
Автор

Can you please make a video of python automation 🙂🙂🙂🙂🙏🙏🙏

lalithamocherla
Автор

You should make a video on different string formatting methods.











i use %-style im weird

creeptitan
Автор

I'm a beginner at python, is this function faster than just use a for loop to find out the data?

Автор

Such a wonderful video! Just what I needed to start using the filter function, with proper if…else clauses!!!

hayleyH
Автор

But how can the function on line 52 get a paramaters while when called on line 58 it doesn't use (arguments)? Can someone explain it for me?

No_Underscore
Автор

How do you magically paste words like that? Real time or time skip?

apocalypticbean
Автор

You didn't need the else. You could have just added return False at the end of the function without the else

FunkatronicGeek
Автор

what colours are you using? great video btw

blizruby
Автор

Hey b001, love the videos! Is there an advantage to using the filter() function over using a list comprehension?

bvdlio
Автор

That is very interesting, never knew that existed...
Is it better/equal to a for loop with if checks?

nyther
join shbcf.ru