Pre-pep discussion material: in-place equivalents to map and filter
Chris Angelico
rosuav at gmail.com
Thu Nov 3 10:05:07 EDT 2016
On Thu, Nov 3, 2016 at 7:29 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>> lst = map (lambda x: x*5, lst)
>> lst = filter (lambda x: x%3 == 1, lst)
>> And perform especially bad in CPython compared to a comprehension.
>
> I doubt that.
>
It's entirely possible. A list comp involves one function call (zero
in Py2), but map/lambda involves a function call per element in the
list. Function calls have overhead.
Arthur, I would suggest looking at what numpy and pandas do. When
you're working with ridiculously large data sets, they absolutely
shine; and if you're not working with that much data, the performance
of map or a list comp is unlikely to be significant. If the numpy
folks have a problem that can't be solved without new syntax, then a
proposal can be brought to the core (like matmul, which was approved
and implemented).
ChrisA
More information about the Python-list
mailing list