LangWart: Method congestion from mutate multiplicty
python.list at tim.thechases.com
Sun Feb 10 14:52:35 CET 2013
On Sun, 10 Feb 2013 22:29:54 +1100, Steven D'Aprano wrote:
> Rick Johnson wrote:
> > map, mapped
> > filter, filtered
> > reduce, reduced
> Those are nonsense. None of those are in-place mutator methods.
> Especially reduce, which reduces a list to a single item. You might
> as well have suggested "len, "lened".
And, if you want those in-place, indexing trivially comes to the
lst[:] = map(transform_fn, lst)
lst[:] = filter(check_fn, lst)
or, as I prefer:
lst[:] = [transform_fn(x) for x in lst]
lst[:] = [x for x in lst if check_fn(x)]
as they can be combined simply.
More information about the Python-list