Hans Mulder writes:
> How about:
> changes = filter(is_bad, d)
> Or would that be too compact?
I thought of writing something like that but filter in python 3 creates
an iterator that would have the same issue of walking the dictionary
while the dictionary is mutating.
changes = list(f
On 08/05/2011 00:12, Roy Smith wrote:
In article<7xd3jukyn9@ruckus.brouhaha.com>,
Paul Rubin wrote:
Roy Smith writes:
changes = [ ]
for key in d.iterkeys():
if is_bad(key):
changes.append(key)
changes = list(k for k in d if is_bad(k))
is a little bit more direct.
This
In article <7xd3jukyn9@ruckus.brouhaha.com>,
Paul Rubin wrote:
> Roy Smith writes:
> > changes = [ ]
> > for key in d.iterkeys():
> > if is_bad(key):
> > changes.append(key)
>
> changes = list(k for k in d if is_bad(k))
>
> is a little bit more direct.
This is true. I still fi
Roy Smith writes:
> changes = [ ]
> for key in d.iterkeys():
> if is_bad(key):
> changes.append(key)
changes = list(k for k in d if is_bad(k))
is a little bit more direct.
--
http://mail.python.org/mailman/listinfo/python-list
...
That works, but if d is large, it won't be very efficient because it has
to generate a large list.
It is not large. But I'm using Python 2.6 , not Python 3.
I did not get this error again in the last two days. I'll post a new
reply if I encounter it again. (It happened just a few times o
In article ,
Peter Otten <__pete...@web.de> wrote:
> You now have to create the list explicitly to avoid the error:
>
> >>> d = dict(a=1)
> >>> keys = list(d.keys())
> >>> for k in keys:
> ... d["b"] = 42
> ...
That works, but if d is large, it won't be very efficient because it has
to gen
As of Python 3.x (which I suspect you are running):
"The objects returned by dict.keys(), dict.values() and dict.items() are view
objects. They provide a dynamic view on the dictionary’s entries, which means
that when the dictionary changes, the view reflects these changes.", and
"Iterating vi
On 4/20/2011 5:52 AM, Laszlo Nagy wrote:
Given this iterator:
class SomeIterableObject(object):
def __iter__(self):
ukeys = self.updates.keys()
for key in ukeys:
if self.updates.has_key(key):
yield self.updates[key]
for rec in self.inserts:
yield rec
How can I get this exce
Mel wrote:
> Laszlo Nagy wrote:
> `ukeys` isn't a different dictionary from `self.updates.keys` I'ts merely
> another name referring to the same dict object. I think
>
> ukeys = dict (self.updates.keys)
>
> would do what you want.
Sorry. Belay that. Thought I'd had enough coffee.
Me
Laszlo Nagy wrote:
> Given this iterator:
>
> class SomeIterableObject(object):
>
>
>
> def __iter__(self):
> ukeys = self.updates.keys()
> for key in ukeys:
> if self.updates.has_key(key):
> yield self.updates[key]
>
Peter Otten wrote:
> Laszlo Nagy wrote:
>
>> Given this iterator:
>>
>> class SomeIterableObject(object):
>>
>>
>>
>> def __iter__(self):
>> ukeys = self.updates.keys()
>> for key in ukeys:
>> if self.updates.has_key(key):
Hm, I see you a
Laszlo Nagy wrote:
> Given this iterator:
>
> class SomeIterableObject(object):
>
>
>
> def __iter__(self):
> ukeys = self.updates.keys()
> for key in ukeys:
> if self.updates.has_key(key):
> yield self.updates[key]
>
Given this iterator:
class SomeIterableObject(object):
def __iter__(self):
ukeys = self.updates.keys()
for key in ukeys:
if self.updates.has_key(key):
yield self.updates[key]
for rec in self.inserts:
yield rec
13 matches
Mail list logo