[Python-ideas] __len__() for map()

Jonathan Fine jfine2358 at gmail.com
Wed Nov 28 09:45:36 EST 2018


On Wed, Nov 28, 2018 at 2:28 PM E. Madison Bray <erik.m.bray at gmail.com> wrote:

> I mostly agree with the existing objections, though I have often found
> myself wanting this too, especially now that `map` does not simply
> return a list.  This problem alone (along with the same problem for
> filter) has had a ridiculously outsized impact on the Python 3 porting
> effort for SageMath, and I find it really irritating at times.

I'm a mathematician, so understand your concerns. Here's what I hope
is a helpful suggestion.

Create a module, say sage.itertools that contains (not tested)

   def py2map(iterable):
        return list(map(iterable))

The porting to Python 3 (for map) is now reduced to writing

    from .itertools import py2map as map

at the head of each module.

Please let me know if this helps.

-- 
Jonathan


More information about the Python-ideas mailing list