[New-bugs-announce] [issue24849] Add __len__ to map, everything in itertools
flying sheep
report at bugs.python.org
Wed Aug 12 12:47:16 CEST 2015
New submission from flying sheep:
Things like progressbars want len() to work on iterated objects.
It’s possible to define __len__ for many of the iterables returned by itertools.
some arguments have to be iterated to find the len(): of course we have to check if those are reentrant, and raise a TypeError if they are non-reentrant. (signified by “(r)→”)
for the predicate functions, it’s questionable if we should offer it, since they might take a long time and “len” is a property-like function that feels like it should return fast.
map(func, iterable) → len(iterable)
count(), cycle(), repeat() → infinty, but because len() returns integers, and there’s only float infinity, that’s impossible
accumulate(iterable) → len(iterable)
chain(*iterables) → sum(len(it) for it in iterables)
chain.from_iterable(iterables) (r)→ like the above
compress(data, selectors) (r)→ sum(1 for s in selectors if s)
dropwhile(pred, iterable) (r)→ for skip, r in enumerate(map(pred, iterable)): if r: return len(iterable) - skip
filterfalse(pred, iterable) (r)→ sum(1 for r in map(pred, iterable) if r)
groupby(iterable[, keyfunc]) (r)→ no way but to actually execute it all
islice(seq, [start,] stop [, step]) → calculatable if len(seq) is possible
starmap(function, iterables) → len(iterables)
takewhile(pred, iterable) (r)→ for skip, r in enumerate(map(pred, iterable)): if not r: return skip
tee(iterable[, n]) → n
zip_longest(*iterables[, fillvalue]) (r)→ max(len(it) for it in iterables)
product(), permutations(), combinations(), combinations_with_replacement() → there’s math for that.
----------
components: Library (Lib)
messages: 248451
nosy: flying sheep
priority: normal
severity: normal
status: open
title: Add __len__ to map, everything in itertools
type: enhancement
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24849>
_______________________________________
More information about the New-bugs-announce
mailing list