I have a list of lists that looks like this:
[['A', 35], ['B', 74], ['C', 21], ['D', 2]]
I want to find the first part of the list based on the second part.
For example, I know I want to get 'C' just by using 21. I know the second part (21) and want to use it to get the first part ('C'). What's the best way to do this?
You should use a dictionary for this:
mylist = [['A', 35], ['B', 74], ['C', 21], ['D', 2]] newdic = dict((y,x) for x,y in mylist) print(newdic)