Message248451
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. |
|
Date |
User |
Action |
Args |
2015-08-12 10:47:16 | flying sheep | set | recipients:
+ flying sheep |
2015-08-12 10:47:16 | flying sheep | set | messageid: <1439376436.18.0.92807776881.issue24849@psf.upfronthosting.co.za> |
2015-08-12 10:47:16 | flying sheep | link | issue24849 messages |
2015-08-12 10:47:15 | flying sheep | create | |
|