This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: itertools.count should work with non-number types
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Mital Ashok, python-dev, rhettinger, veky
Priority: normal Keywords: patch

Created on 2022-01-29 19:14 by Mital Ashok, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31013 closed python-dev, 2022-01-29 19:21
Messages (3)
msg412095 - (view) Author: Mital Ashok (Mital Ashok) * Date: 2022-01-29 19:14
There's no reason that `count('', 'a')` for `'', 'a', 'aa', ...` or `count((), (1,))` for `(), (1,), (1, 1), ...` shouldn't work.

count(a, b) should be equivalent to accumulate(chain((a,), repeat(b)))

The docs don't strongly suggest that it won't work (it says *start* is a number, but the "roughly equivalent to" generator would work for str/tuple/etc)
msg412108 - (view) Author: Vedran Čačić (veky) * Date: 2022-01-29 22:39
At one moment, I had a need for 

    itertools.count(, datetime.timedelta(days=1))

Of course, it was no problem to write it myself, but still, it would be incredibly neat if it simply worked.
msg412128 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2022-01-30 05:42
Thanks for the suggestion but I'm going to decline.

* The need for this is very low.  

* It's easy to roll your own.

* The code for `count('', 'a')` and `count((), (1,))` isn't intelligible.

* Without special casing, the code for `count('', 'a')` and `count((), (1,))` is highly inefficient.  We advise people not to use the 's = s + t' pattern in a loop for sequences because it leads to quadratic behavior.
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90732
2022-01-30 05:42:19rhettingersetstatus: open -> closed

assignee: rhettinger

nosy: + rhettinger
messages: + msg412128
resolution: rejected
stage: patch review -> resolved
2022-01-29 22:39:14vekysetnosy: + veky
messages: + msg412108
2022-01-29 19:21:42python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request29192
stage: patch review
2022-01-29 19:14:25Mital Ashokcreate