[issue33049] itertools.count() confusingly mentions zip() and sequence numbers

Raymond Hettinger report at bugs.python.org
Mon Mar 12 01:07:35 EDT 2018


Raymond Hettinger <raymond.hettinger at 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 at python -> rhettinger
priority: normal -> low

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


More information about the Python-bugs-list mailing list