Earlier quoted context omitted.
Usually list comprehensions are a much cleaner way to write a map. This I love. Personally what I love most about using more functional code aren't the clever lambda's and stuff, I actually try to avoid that because it looks weird in Python. What's really awesome is enclosing named functions inside bigger functions and using closures. The result is code where: 1. nobody can, by accident or intentionally, use inner fu…
> Usually list comprehensions are a much cleaner way to write a map. But the first makes my intent clearer than the second: map(f, xs) [f(x) for x in xs] In Python, where creating anonymous functions is syntactically expensive, list-comprehension syntax may be cheaper in many cases, but it's not clearer. When I want to map or filter something, I want to _say_ that I'm mapping or filtering, not explain to Python how t…
ids = [item.id for item in all_items]
Seems much cleaner than ids = map(lambda item: item.id, all_items)
But yes, I agree, when you have to actually perform some less-than-trivial computation on every item of a list, map is much cleaner.