Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

Scott David Daniels scott.daniels at acm.org
Sat Jul 1 17:02:01 EDT 2006


cmdrrickhunter at yaho.com wrote:
> I can't speak for your code, but this is the most common use of keys in
> my coding:
> # d is some dictionary
> keys = d.keys()
> keys.sort()
> for k in keys:
>   #blah

This you can rewrite quite effectively as:

     for k in sorted(d):
         #blah

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list