Python Devs Always FORGET That THIS Exists

preview_player
Показать описание
Python deves always forget that this exists
Рекомендации по теме
Комментарии
Автор

if comprehension doesn't have [] around it, it's not list comprehension, it's generator comprehension

dp.
Автор

As others have said, nitpick here: you aren't using a list comprehension but a generator (which is the way you should be doing any and all so they can short circuit before having to generate the entire list). A list comprehension of any or all would be:

any([....])
all([....])

Please, people reading this: do not use list comprehensions with any and all. Do generator comprehensions like in this video.

vorpal
Автор

How satisfying it is to learn one new thing from you every single day ❤

DaryaIbrahim
Автор

just 2 days ago i used an absurd amount of (if 'str' in z or 'str1' in z ....) I knew something like this existed and chatGPT pointed exactly this.

Thank you for educating about this, this is a must know.

shafaitahir
Автор

ChatGPT explained to me that if there are no brackets “[]” then it is a “generator expression”, not a list comprehension. An important difference is the generator is “lazy”, just like a generator function using “yield” instead of “return”, giving one result at a time rather than iterating over the entire list first. So a generator expression can replace something like a more complicated next(filter(lambda)) expression for getting to a result faster than a list comprehension might. I am absolutely shocked that I know this now. 😂

RedBearAK
Автор

Correct title would be: Junior Python Devs Sometimes Forget That THIS Exists

kpbendeguz
Автор

ive seen a lot of beginners stuffs and basic python functions being posted as things python devs forget in youtube lately lol. learn your basics kids.

ashimdahal
Автор

You could also use any(map() with a lambda function, like any(map(lambda n: n>0))

angelapaun
Автор

This is the same as running a loop manually

CodersHaven
Автор

İ didn't know you learned it today

elcanpenahov
Автор

From numpy import *

Will break this code since no.any is different from the built in

DrDeuteron
Автор

And if you wanna check if any element in one list is in the other, u just go like...

if any in listOne in listTwo:
...

Contemelia
Автор

You don't need list comprehension here, list can be used directly like

if all(l):

АлександрКоновалов-шн
Автор

you don't need to use this function at all in this case, instead you can utilize the functionality that a list will return true or false based on if its empty or not

example:
if [x for x in list if x > 6]:

Logically this would be slightly faster, though only really mattering for big lists. Logic being of-course that looping over something twice takes longer than doing so once and then reading an attribute. Correct me if wrong

ferretdevshit
Автор

Bro that's a generator expression, not a list comprehension 😒😑

aflous
Автор

does this method uses short circuit? (it stop evaluating after first True?)

rooftop
Автор

Thanks mate, what colour scheme is that btw and is it vscode?

bertrodgers
Автор

JavaScript method


l = [-1, 2, 5, 4];
result = l.every((n)=>{
n>0;
});
console.log(result);

l = [-1, 2, 5, 4];
result2 = l.some((n)=>{
n>0;
});
console.log(result2);

Bebabana
Автор

Isn't any() function used to find whether a variable is null or not ??

randomcreations
Автор

You don’t technically need both the any() and all() functions, because of De Morgan’s theorems:

not any(p(x) for x in l) <=> all(not p(x) for x in l)
not all(p(x) for x in l) <=> any(not p(x) for x in l)

But I guess particular forms might be clearer in particular cases ...

lawrencedoliveiro