Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



Yeah, I prefer the dict comprehension.

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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: