On Fri, Jun 19, 2020 at 12:29 PM Ricky Teachey <ri...@teachey.org> wrote:
> On Fri, Jun 19, 2020 at 12:25 PM <ke...@edinburghacademy.org.uk> wrote: > >> Proposal: >> range(start, ..., step) >> should function like >> itertools.count(start, step) >> >> Reason: >> It's pretty common to see people do things where they increment a count >> within a while True loop, and it would be nice to have something easily >> available for people to use to replace this. >> >> Usefulness: >> There is definitely a use for this, as the type of code mentioned above >> is common, and itertools.count is commonly used as well. >> > > If the primary reason is usage in a for loop, why is itertools.count not > already sufficient? > Per my previous response, I don't find the reason given by the OP to be very convincing. However there's another possible reason to want to do this. I have more than once wanted to have infinite ranges that are analogous to infinite slices: slice(None) <=> range(0, infinity or perhaps None) slice(1, None) <=> range(1, infinity or perhaps None) slice(-1, None, -1) <=> range(-1, infinity or perhaps None, -1) It is hard for me to remember the contexts in which I was wanting to have this equivalency available. Making something up off the top of my head (but probably not very convincing on its own), this way it is easy to do things like: interesting_indexes_list =[ range(1, 11), range(11, 100), range(100, None) ] for rng in interesting_indexes_list: if really_interesting_index in rng: frobnicate_seq_slice(my_seq[rng.start:rng.stop:rang.step])
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/5AHECGRACGHUT2Y3XB3JLBSMMBG6KAPH/ Code of Conduct: http://python.org/psf/codeofconduct/