2 ms·
I learned both around the same time, but even in good functional languages like Haskell, using a comprehension for anything more than simple problems results in
by hajile 11y ago
I learned both around the same time, but even in good functional languages like Haskell, using a comprehension for anything more than simple problems results in an unreadable mess.
map or filter are much easier to read for complex data manipulations and as a bonus, their composition rules make it easy to increase performance. For example, if you see two map functions together, you can wrap them in a compose and only map over your elements once. This isn't as immediately obvious when you're using comprehensions.
- m_mueller 11y agoCould you give an example? Do you mean something like > [ manager.name for manager in set([ person.manager for person in employees ])] ? I assume with something like set() or unique() you need to create the intermediate iterable anyway, but without it I have trouble finding an example where doing a single list comprehension wouldn't suffice.