removing items from a dictionary ?

Paul Rubin http
Thu Jul 26 17:02:46 EDT 2007


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)



More information about the Python-list mailing list