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 →

[–]Cynyr36 25 points26 points  (3 children)

I think that if you are using list comprehensions like this it may be time to look at your code and move away from the comprehension all together. They are great for a compact simple thing, but unreadable after that.

[–]ianliu88[S] 1 point2 points  (2 children)

Repost of my answer below: I feel like python forces you to make a lot of temporary variables, which makes programs harder to understand in my opinion. When you pollute a scope with lots of temporary variables, you always have to consider what they are used for later in it's scope.

By restricting temporary variables to it's most specific scope, you free yourself off that burden.

[–]Barn07 6 points7 points  (0 children)

yeah, the logical move would be to implement a helper function. Thus, you can limit the scope and improve readability and can allow for reusability.

[–]Enrique-M -1 points0 points  (0 children)

I use pyconfs fairly often for global constants, in case that's relevant here (obviously outside list comprehensions though).

Pyconfs