[Baypiggies] list to dictionary problem

Vikram kpguy at rediffmail.com
Tue Jun 22 04:22:53 CEST 2010

Suppose i have this list:

>>> a = [['cat',2],['cat',5],['cat',9],['dog',6]]
>>> a
[['cat', 2], ['cat', 5], ['cat', 9], ['dog', 6]]

Now, there is a nice way to obtain the value 9.

>>> z = dict(a)
>>> z
{'dog': 6, 'cat': 9}

Is there any elegant way to extract the value 2? (Value corresponding to the first occurence of 'cat' in the 2-D list).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100622/2bd50c29/attachment-0001.html>

More information about the Baypiggies mailing list