On Wednesday 05 November 2003 22:44, Samuele Pedroni wrote: ... > > > I think he was wondering whether people rely on > > > > > > enumerate([1,2]).next ...which is one thing... > > > i = enumerate([1,2]) > > > i is iter(i) ...which is another. > >Ah, I see -- thanks! Well, in theory you COULD add a 'next' method too: Note I specifically didn't say "make enumerate return an iterator" -- I said "add a 'next' method". It's a non-special name (be that right or wrong) and thus there is no prohibition against non-iterators having such a method. > well, you would also get an iterator hybrid that violates: No you wouldn't -- you would get a non-iterator type which exposes a method named 'next', and that violates no Python rule. > attach __reversed__ to an iterator, making enumerate just an iterable is > not backward compatible but is a bit saner although it does not feel that > natural either. If anybody relies on that "i is iter(i)" then, yes. I have never seen that relied upon. I _have_ seen quite a few cases of reliance on calls to a 'next' method to "throw the first item away" (no doubt a call to iter(...) first would be preferable, but I'm just mentioning what I've seen). I'm not sure supporting dubious "happens to work" existing usage is _desirable_ -- I'm just saying it's _possible_ (in some cases, such as this one) without necessarily violating anything. Personally, since I found out that enumerate(reversed(x)) works almost as well as reversed(enumerate(x)) [[or other hypotheticals -- such as enumerate(x, reverse=True) OR reversed(x, enumerate=True)]], and better than revrange(len(x)), for my use cases, I'm not particularly pro NOR con wrt __reversed__ -- its pluses (which Raymond summarizes quite well) and its minuses (Guido's worry about it promoting unwarranted complications, my vague unease at "yet another special-case protocol via a special-method when adaptation would handle it more uniformly") are finely balanced. I just hope that, either with or without __reversed__, reversed _does_ get in, at least, as Guido pointed out, tentatively (since features, if need be, may be withdrawn before the beta phase). Alex
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4