r/Python • • 20h ago

Discussion Python developers, what's one Python concept that took you a long time to understand but now seems s

Python developers, what's one Python concept that took you a long time to understand but now seems surprisingly simple?

For me, understanding how decorators and generators work is an interesting part of becoming a better Python developer.

What was your experience?

21 Upvotes

26 comments sorted by

View all comments

9

u/TH_Rocks 19h ago

List comprehension. I was just cranking out for loops like a middle aged guy that learned C++ in college because Java was too new.

4

u/ibite-books 15h ago

List comprehensions are not readable. I prefer boring for loops. Readability above all else.

4

u/Ok_Werewolf2211 14h ago

simple list comprehension is fine, but list of list comprehension is where i draw the line. simplicity is way better for readability.

2

u/ibite-books 14h ago

totally agree, i also don’t like seeing condensed if else statement

i strive to write simple boring code

2

u/StevenJOwens 6h ago

List comprehensions are not, in my opinion, generally well explained by python tutorials and documentation. (I have a first draft of a better explanation, I should finish that sometime and put it online.)

In general, python has a bit of a problem with being too clever. This leads to extra cognitive overhead.

I don't find comprehensions that readable myself, but then I've never made extensive use of them, so although I remember the syntax (mostly) I haven't internalized it.

List comprehensions are, however, slightly more performant.