"Chorn, Guillaume" <guillaume_ch...@merck.com> wrote

dictionary, but can I look up the key associated with a particular
value?

Not directly but its not hard to do bearing in mind you will get a collection back.:

d = {1:10,2:20,3:10,4:20}
val = 10
ks = [k for k in d if d[k] == val]
ks
[1, 3]


You need to trawl the dictionary whatever you do
(unless you get very sophisticated and build a double dictionary class, but then insertions get slow because you have to update both versions...)

HTH,

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


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to