Tricky Dictionary Question from newbie

Cyril Bazin cyril.bazin at gmail.com
Mon Jul 11 14:24:44 EDT 2005


Hum... I think an iteritems is better, this way, python don't need to create 
in memory 
a complete list of couple key, value.

On 7/11/05, Markus Weihs <mweihs at gmx.at> wrote:
> 
> Hi!
> 
> 
> Dict = {'rt': 'repeated', 'sr':'repeated', 'gf':'not repeated'}
> NewDic = {}
> 
> for k,v in Dict.items():
> NewDic.setdefault(v, []).append(k)
> 
> 
> Regards, mawe
> 
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050711/7f36c136/attachment.html>


More information about the Python-list mailing list