removing items from a dictionary ?
Stef Mientki
S.Mientki-nospam at mailbox.kun.nl
Thu Jul 26 18:01:05 EDT 2007
Paul Rubin wrote:
> Stef Mientki <S.Mientki-nospam at mailbox.kun.nl> writes:
>>> for net in Nets.keys():
>>> # Nets.iterkeys() would avoid building the list
>>> # but that runs the same risks as your original
>>> if net.upper() in in Eagle_Power_Nets :
>>> del Nets[net]
>>>
>> thanks Steve,
>> that does the job.
>
> Depending on the relative sizes of those dicts, maybe
> you want to try rebuilding instead of deleting. Untested:
>
> Nets = dict((k,v) for k,v in Nets.itervalues()
> if k.upper() not in Eagle_Power_Nets)
thanks Paul,
this is a very interesting idea,
especially while my dictionaries are quit small,
and I have to do some more complex things other than delete.
cheers,
Stef Mientki
More information about the Python-list
mailing list