removing items from a dictionary ?

Stef Mientki S.Mientki-nospam at
Fri Jul 27 00:01:05 CEST 2007

Paul Rubin wrote:
> Stef Mientki <S.Mientki-nospam at> 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.

Stef Mientki

More information about the Python-list mailing list