Not this one the other one, from a dictionary

Ross rossgk at
Fri Sep 18 18:28:44 CEST 2009

Learning my way around list comprehension a bit.   I wonder if  
someone has a better way to solve this issue.  I have a two element  
dictionary, and I know one of the keys but not the other, and I want  
to look up the other one.

So I have this dictionary:

aDict = {'a': 'bob', 'b': 'stu'}

I know that the dictionary contains two keys/value pairs,  but I  
don't know the values nor that the keys will be 'a' and 'b'.   I  
finally get one of the keys passed to me as variable BigOne. e.g.:

BigOne = "a"

The other key, call it  littleOne remains unknown.  It might be "b"  
but could be "c", "x", etc...   I later need to access both values...

I have something that works, with list comprehension - but wonder if  
there's a more brief/elegant way to get there:

BigValu = aDict[BigOne]
temp =  [ thing for thing in aDict if thing != BigOne ]
LittleValu = aDict[ temp[0] ]

Any thoughts?

- Ross.

More information about the Python-list mailing list