4 ms·
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 http://pa
by cuu508 12y ago
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 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.
- meowface 12y agoYeah, I prefer the dict comprehension. I use dict comprehensions quite frequently in my own code as well.