Dictionary comprehension

Greg Ewing see at my.signature
Tue Jun 12 01:44:49 EDT 2001


Magnus Lie Hetland wrote:
> 
>   inverted = {dict[key]:key for key in dict}

If the for key:value in dict syntax ever got approved,
this would look really nice:

  tcid = {val:key for key:val in dict}

Almost a palindrome... :-)

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list