Use any() and all() to refactor your Python code! #shorts

preview_player
Показать описание
Use any() and all() to refactor your Python code! #shorts

Get my Free NumPy Handbook:

📓 ML Notebooks available on Patreon:

If you enjoyed this video, please subscribe to the channel:

~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

#Python
Рекомендации по теме
Комментарии
Автор

Note the duality:

any(x for x in y) == not all(not x for x in y)
all(x for x in y) == not any(not x for x in y)

or alternatively

not any(x for x in y) == all(not x for x in y)
not all(x for x in y) == any(not x for x in y)

as a consequence of De Morgan’s theorems.

lawrencedoliveiro
Автор

"all" is "and" in disguise, "any" is "or" in disguise.

GabrielsEpicLifeofGoals
Автор

Been learning Python and writing programs the past couple of months and your videos have been tremendously helpful.

FrocketGaming
Автор

I'm skeptical, because it's going to do exactly what the for loop is going to do. However the for loop is going to be optimized with C. Any or All will make your code slower

thierrybeaulieu
Автор

Logic gates emulating logic gates, love it

IdioticMath
Автор

very useful pat, found it today - there is also a sum built-in; sum also works with a list of booleans :)

pattmehta
Автор

Hey, quick question I know the all method is shorter to write but isn't the for loop faster as sometimes it doesn't have to loop through the whole loop. All and any are powerful but I would only use them if the list is already contains only booleans or similar cases?

jovaraszigmantas
Автор

Your videos are fantastic. Thanks for such tips :)

raminmousivand
Автор

Note that "any" and "all" returns true if you will pass an empty list to it.

vanya
Автор

Good stuff! Gotta love when you can make code shorter.

WhyNotProgram
Автор

I knew both functions, but i never expect the actual usage was something like this, thanks so much

muuur
Автор

Wow. Somehow I always forget stuff like that and do it like I used to do it all the time. Nice work Patrick!

fastrockstar
Автор

This is awesome. I will just suggest you use a better quality microphone for videos.

ninjanape
Автор

These python junkies will go to any length to make everything one liner, whatever the cost maybe.

cipherxen
Автор

So generator is faster then simply any(numbers) ?

piotr
Автор

God I wish you could save youtube shorts

Vlakoosh
Автор

wow so many hidden utilities in this language

NikkiMcMistie
Автор

How do you keep all that handy stuff in your mind?

MrJonas
Автор

Is any or all faster than manual looping?

imlazy
Автор

Still lacking in terms of javascript's some and every method

Shyam_Mahanta