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