Modify dict/set during iteration?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Fri Oct 30 03:21:35 EDT 2009
On Thu, 29 Oct 2009 21:14:22 -0700, metal wrote:
> Maybe my real goal is the following:
>
> def miter(iterable):
> for x in tuple(iterable):
> if x in iterable:
> yield x
I don't think that does what you think it does. For some iterables it
doesn't do anything at all:
>>> it = iter([1,2,3])
>>> for item in miter(it):
... print item
...
>>>
and for others it is redundant:
>>> it = [1,2,3]
>>> for item in miter(it): # same as `for item in it:`
... print item
...
1
2
3
>>>
Could you explain what you are trying to accomplish?
--
Steven
More information about the Python-list
mailing list