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

Chris Angelico rosuav at gmail.com
Mon Nov 26 19:02:31 EST 2018


On Tue, Nov 27, 2018 at 10:41 AM Steven D'Aprano <steve at pearwood.info> wrote:
>
> On Tue, Nov 27, 2018 at 09:36:08AM +1100, Chris Angelico wrote:
>
> > Don't forget, too, that map() can take more than one iterable
>
> I forgot about that!
>
> But in this case, I think the answer is obvious: the length of the map
> object is the *smallest* length of the iterables, ignoring any unsized
> or infinite ones.

Equally obvious and valid answer: The length is the smallest length of
its iterables, ignoring any infinite ones, but if any iterable is
unsized, the map is unsized.

And both answers will surprise people.

I still think there's room in the world for a "mapped list view" type,
which retains a reference to an underlying list, plus a function, and
proxies everything through to the function. It would NOT have the
flexibility of map(), but it would be able to directly subscript, it
wouldn't need any cache, etc, etc.

ChrisA


More information about the Python-ideas mailing list