[Tutor] How to print corresponding keys in Dictionary

Alan Gauld alan.gauld at btinternet.com
Tue Oct 25 01:48:05 CEST 2011


On 24/10/11 19:00, Alan Gauld wrote:
> For fun:
>
> def getKeys(aDict, aValue):
>     return [key for key,val in aDict if val == aValue]

Oops, that should have been

      return [key for key,val in aDict.items() if val == aValue]


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list