4 ms·
Comprehension in Python
- gamegoblin 14y agoGood 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.
- benn_88 14y agoThanks. Good point - I've added a bit at the end stating it's not always the way to go.