splitting one dictionary into two

Robert Brewer fumanchu at amor.org
Thu Apr 1 12:42:57 EST 2004


jsaul wrote:
> I think the most "pythonic" candidate is actually the version
> suggested by Larry, namely
> 
>     for key in dict1.keys():
>         if dict1[key] > 3:
>             dict2[key] = dict1.pop(key)

The problem with this one is that, if dict1 is also large, then using
dict1.keys() is going to be expensive.


FuManChu




More information about the Python-list mailing list