Thanks Dave. Actually I figured out a relatively simple solution to my specific problem--since the dictionary I made was the result of zipping together two lists, I simply made a second dictionary with the lists switched around after the zip command and used that. It worked in my case because all key-value pairings were unique...
-----Original Message----- From: Dave Angel [mailto:da...@ieee.org] Sent: Monday, August 16, 2010 4:03 PM To: Chorn, Guillaume Cc: tutor@python.org Subject: Re: [Tutor] Question about Dictionaries Chorn, Guillaume wrote: > Hi All, > > I know that I can look up the value for a particular key in a > dictionary, but can I look up the key associated with a particular > value? I understand that this could be problematic from the standpoint > of multiple keys having the same value, but even then I feel like Python > could just return a list of keys with that value. > > Thanks! > > Guillaume > > Notice: This e-mail message, together with any attachments, contains > information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, > New Jersey, USA 08889), and/or its affiliates Direct contact information > for affiliates is available at > http://www.merck.com/contact/contacts.html) that may be confidential, > proprietary copyrighted and/or legally privileged. It is intended solely > for the use of the individual or entity named on this message. If you are > not the intended recipient, and have received this message in error, > please notify us immediately by reply e-mail and then delete it from > your system. > > As long as you don't mind it being (relatively) slow, you could do something like (untested): [key for key, item in mydict if item == value] DaveA Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates Direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor