News for hackers. Stuff that matters.
Re:Functional Programming in Python [pdf] by m_mueller on Friday July 24, 2015 @07:24PM (#9945833)
> 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.

Re:Functional Programming in Python [pdf] by hajile on Friday July 24, 2015 @07:47PM (#9945908)
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.

Re:Functional Programming in Python [pdf] by m_mueller on Friday July 24, 2015 @10:43PM (#9946339)
Could 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.