[issue33049] itertools.count() confusingly mentions zip() and sequence numbers
New submission from Trey Hunner <trey@truthful.technology>:
From the itertools documentation: https://docs.python.org/3/library/itertools.html?highlight=itertools#itertoo...
Also, used with zip() to add sequence numbers.
I'm not certain what the goal of the original sentence was, but I think it's unclear as currently written. I assume this is what's meant: my_sequence = [1, 2, 3, 4] for i, item in zip(count(1), my_sequence): print(i, item) This is a strange thing to note though because enumerate would be a better use here. my_sequence = [1, 2, 3, 4] for i, item in enumerate(my_sequence, start=1): print(i, item) Maybe what is meant is that count can be used with a step while enumerate cannot? my_sequence = [1, 2, 3, 4] for i, item in zip(count(step=5), my_sequence): print(i, item) If that's the case it seems like step should instead be mentioned there instead of "sequence numbers". ---------- assignee: docs@python components: Documentation messages: 313606 nosy: docs@python, trey priority: normal severity: normal status: open title: itertools.count() confusingly mentions zip() and sequence numbers type: enhancement versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33049> _______________________________________
Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment: For example zip(my_sequence, count(1)). ---------- nosy: +rhettinger, serhiy.storchaka _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33049> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment:
This is a strange thing to note though because enumerate would be a better use here.
IIRC, the wording predates the addition of enumerate() and before enumerate() grew a *start* argument. That said, enumerate() just addresses care the most common case. It is still worth mentioning that count() is still useful for the general case of adding sequence numbers to data streams woven together by zip() -- like the way auto-increment is used in SQL: from time import ctime def timestamp(): while True: yield ctime() def user_request(): while True: yield input() logged_requests = zip(user_request(), count(1), timestamp(), cycle(available_servers))
it seems like step should instead be mentioned there instead of "sequence numbers".
The *step* argument was a late addition to the API and isn't used much in practice. When it is used, its meaning and use case tend to be self-evident (i.e. counting 60 seconds at a time, or counting backwards), so it doesn't warrant further elaboration. The sentence as-is is imperfect (it makes you wonder why not just use enumerate) but it seems better than either saying less by not mentioning the use case or getting too wordy which would place too much emphasis on use cases less common that those served by enumerate(). So, my preference is to leave the sentence as it stands. The intent of the two sentences mentioning map() and zip() was to hint at the possibilities while still keeping the paragraph primary focused on what count() actually does. ---------- assignee: docs@python -> rhettinger priority: normal -> low _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33049> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: I think 'sequential numbers' would be slightly better than 'sequence numbers'. To be, it better includes stepped and descending sequences. (Enough better that I would be willing to do the PR and merge.) Otherwise, I think leave it alone. ---------- nosy: +terry.reedy versions: -Python 3.4, Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33049> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: Since I don't like "sequential numbers", let's opt for the "leave it alone" option :-) ---------- resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33049> _______________________________________
participants (4)
-
Raymond Hettinger
-
Serhiy Storchaka
-
Terry J. Reedy
-
Trey Hunner