3 ms·
I'm not a regular python user but the article did mention that map is somehow not pythonic.
by Scarbutt 11y ago
I'm not a regular python user but the article did mention that map is somehow not pythonic.
- masklinn 11y agoYup apparently an earlier version of the article used `map` and someone complained that it's not pythonic. `map` using a lambda may be undesirable compared to a listcomp, but if you already have a function doing exactly what you want it's perfectly fine. Though in this case a better (existing) function is `operator.add`.
- bpicolo 11y agooperator.add doesn't scale to n lists. Would be weird in this case as well. You'd need: map(lambda x: operator.add(*x), zip(x, y)) map might not be `pythonic` but I typically pull out map/reduce/filter for the trivial cases. filter(bool, list_) is just as understandable as [i for i in list_ if i]