3 ms·
> It may just be a matter of which a person learned first. I think this is the case, for me map is much harder to read. But I also think that comprehensions go
by m_mueller 11y ago
> It may just be a matter of which a person learned first.
I think this is the case, for me map is much harder to read. But I also think that comprehensions go back to math sets, so I was familiar with this even before learning any programming. Therefore comprehensions clicked immediately for me and it's by far my favourite python feature.
- hajile 11y agoI 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.