[New-bugs-announce] [issue32172] Add length counter for iterables

bugale bugale report at bugs.python.org
Wed Nov 29 18:00:53 EST 2017


New submission from bugale bugale <bugalit at gmail.com>:

I have noticed that there is no convenient way in python to get the number of items in a generator.

For example:
  my_iterable = iter(range(1000))
  len(my_iterable) # Would not work

Of course, something like this would ruin the generator, and it will no longer be usable, but in some use cases one would like to know only the count of something.

It is possible to do it today using this line:
  sum(1 for x in my_iterable)

but it seems odd to me that there is no function like:
  itertools.count_iterable(my_iterable)
that does exactly this

----------
components: Demos and Tools
messages: 307271
nosy: bugale bugale
priority: normal
severity: normal
status: open
title: Add length counter for iterables
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32172>
_______________________________________


More information about the New-bugs-announce mailing list