A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-July/026847.html below:

[Python-Dev] Re: The iterator story

[Python-Dev] Re: The iterator storyOren Tirosh oren-py-d@hishome.net
Sat, 20 Jul 2002 09:39:26 -0400
On Sat, Jul 20, 2002 at 05:45:48AM -0700, Ka-Ping Yee wrote:
> > To summarize, I agree that "for" mutating the object can be surprising.
> 
> The rub is, the only way for it to *not* be surprising is to have a
> way to *say* "loop destructively".  If you can't express your
> expectations, there's no way to meet them.

It doesn't seem very useful to say "loop destructively" - in these cases I
don't usually care whether it's destructive or not.  It is useful, though, 
to be able to say "loop INdestructively".  

That's how I do it:

def reiter(obj):
    """ Return an object's iterator, raise exception if object does not
appear to support multiple iterations """
    assert not isintance(obj, file)
    itr = iter(obj)
    assert itr is not obj
    return itr

	Oren




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