Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Comprehension in Python (bennuttall.com)
9 points by ColinWright on Jan 28, 2013 | hide | past | favorite | 2 comments



Good post. It always surprises me to meet intermediate+ Python programmers who don't know about Dict or Set comprehensions, so good on you for spreading the gospel.

That being said, I find that whenever I make heavy use of comprehensions, I am often tempted by some evil urge to get sucked into ludicrously nested comprehensions leading to unreadable code.

It's not hard to fight these urges, when you get say, 2 lines deep and 4 nested comprehensions, but comprehensions do make it easy to obfuscate otherwise clear code.

Some things are better expressed as a comprehension, some things are not. So I suppose we must be constantly aware of the readability of our code.


Thanks. Good point - I've added a bit at the end stating it's not always the way to go.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: