THIS Python Trick Seriously CHANGED My Life

preview_player
Показать описание
This Python trick seriously changed my life. #python #code #shorts
Рекомендации по теме
Комментарии
Автор

same damn thing with a lower readability

Pardenoeo
Автор

I’ve never seen the benefit other than cleaner code. At the cost of becoming less readable/intuitive and no efficiency gains. It still feels like a ‘my epenis is bigger than yours’ play, but by all means: proof me wrong!

BelovedNL
Автор

List comprehension has always been a tad confusing and haven’t gotten it yet but this makes it clear as day.

milesstripling
Автор

My take: if there are two "for"s in a list (or any iterable) comprehension, it shouldn't be a list comprehension. Two regular for loops are better readable and understandable, and even a comprehension in a for loop is more acceptable

zgliu
Автор

Flat map is easier to read/reason and consistent with other languages like Scala and JavaScript

harisnadeem
Автор

The location of “if” inside the comprehension greatly matters as well, should you have to use it.

JordanMetroidManiac
Автор

The only issue with list comprehension is that it keeps a new list in memory, and in the event of a very long list, it can cause memory issues.

alireza
Автор

Oh that's a good way to explain it, I always found nested list comprehension a bit confusing

alkebabish
Автор

Don't use list comprehension for more than 1 for-loop

gaaraxpo
Автор

Nested for loops have some downsides. Like time complexity of n squared. Which is fine for a list of 2 elements but not OK if you collection is much much larger...

linatroshka
Автор

There's any other reason, beside being adults?

PabloBianchiOK
Автор

That’s not a trick. That is just python 101 and surprising if you’re coming from java or so…

stevengorlich
Автор

Does using list comprehensive reduce the time complexity of this code?

Ayotundejerry
Автор

for what purpose? this is still o(n^2)

Kuba-zljp
Автор

I learned this correct the first time. So no need to revisit. I love comprehensions

ProjectBimmers
Автор

Using a generator and yielding each element within each nest is another approach...

ThothAmon
Автор

The comprehension does something completely different than what the double for loop does.. at least keep it consistent.

MyManJohnny
Автор

What did the Python developers think here? Clearly the logical thing would be to have the for terms in opposite order in the list comprehension.

__christopher__
Автор

nice, thats a neat way of thinking about it

ahmednishaal
Автор

I didnt want to learn them yet and bro just explained it to me fucking perfectly

therealchicken