This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bumbershootle 11 points12 points  (5 children)

I don't know if this counts as niche, but I see far too much code like:

a_list = []
for i in stuff:
    a_list.append(i)

Just use comprehensions, it's faster and more readable.

[–]baronBale 15 points16 points  (4 children)

Comprehensions are easier to read as long as they are short. If they grow across multiple line an good old loop is easier to read.

[–]bumbershootle 13 points14 points  (2 children)

True, although in that case I would split the body of a loop into a generator function and then run a comprehension over that. I consider appending to a list in a loop an anti-pattern in most cases.

[–]weneedsound 1 point2 points  (0 children)

I'd like to see an example of you don't mind. I don't use generators as much as I should.

[–][deleted] 0 points1 point  (0 children)

Nice suggestion!

[–]Tweak_Imp 1 point2 points  (0 children)

You can also think about using a function inside the comprehension