[Python-Dev] [Python-ideas] Expose itertools.count.start
and implement itertools.count.__eq__
based on it, like range
. (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Sat Jun 7 11:50:50 CEST 2014
- Previous message: [Python-Dev] namedtuple implementation grumble
- Next message: [Python-Dev] [Python-ideas] Expose `itertools.count.start` and implement `itertools.count.__eq__` based on it, like `range`.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 7 June 2014 19:36, Ram Rachum <ram.rachum at gmail.com> wrote:
My need is to have an infinite immutable sequence. I did this for myself by creating a simple
count
-like stateless class, but it would be nice if that behavior was part ofrange
.
Handling esoteric use cases like it sounds yours was is why user defined classes exist. It does not follow that "I had to write a custom class to solve my problem" should lead to a standard library or builtin changing unless you can make a compelling case for:
- the change being a solution to a common problem that a lot of other people also have. "I think it might be nice" and "it would have been useful to me to help solve this weird problem I had that one time" isn't enough.
- the change fitting in conceptually with the existing language and tools. In this case, "infinite sequence" is a fundamentally incoherent concept in Python - len() certainly won't work, and negative indexing behaviour is hence not defined. By contrast, since iterables and iterators aren't required to support len() the way sequences are, infinite iterable and infinite iterator are both perfectly well defined.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] namedtuple implementation grumble
- Next message: [Python-Dev] [Python-ideas] Expose `itertools.count.start` and implement `itertools.count.__eq__` based on it, like `range`.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]