--

Python map and filter return iterables for a good reason. It allows them to be chained without the overhead of creating an in-memory list at each step in the chain.

If you specifically require a list as a result, a list comprehension is a better solution. But when performing complex multi-step, iterable chaining is extremely useful.

Also, in your reduce example, there is no need to define an add function. Python has function equivalents of all its operators in the operator module.

I don't think this article is a fair comparison, it really just shows that (I guess) you are more experienced with Ruby than Python.

--

--

Martin McBride
Martin McBride

No responses yet