News for hackers. Stuff that matters.
Re:Anti-Patterns in Python Programming by meowface on Wednesday July 09, 2014 @08:44AM (#8009316)
I'm a bit torn on it.

In a case where you need to do a lot of nested appends, I've found that even a long list comprehension can be easier to read. You just have to be sure to properly indent it and break it up into multiple lines. My rule is that every extra `for` starts a new line, and sometimes moving the predicate to its own line when it's too long, too.

Re:Anti-Patterns in Python Programming by cuu508 on Thursday July 10, 2014 @05:31PM (#8017465)
For a concrete example, I was just recently converting a list-of-dicts into a dict-of-dicts. Here's an isolated snippet:

http://pastebin.com/8q46bK0v

To my eye, the list comprehension version is reasonable. But I like the imperative style better: it uses the most basic language features and at a glance you can tell what it does. My favourite is the dictionary comprehension version, it's the shortest but still conveys clearly what it's doing.

Re:Anti-Patterns in Python Programming by meowface on Thursday July 10, 2014 @08:51PM (#8018322)
Yeah, I prefer the dict comprehension.

I use dict comprehensions quite frequently in my own code as well.