Question: I have a dict of tuples such as: 

```
d = {'a': (3, 5), 'b': (5, 8), 'c': (9, 3)}  

```

I want to return the key of the minimum of the tuple values based on the tuple index. For example, if using tuple index = 0, then 'a' would be returned. if index = 1, then 'c' would be returned. I have tried using min(), for example 

```
min(d, key=d.get)

```

but am not sure how to manipulate it to select the tuple index to use. Although there are similar questions, I have not found an answer to this. Apologies in advance if this is a duped question, and please link to the answer. Thanks

Answer: 
You can write a lambda function to get the elements from the value by their index:

```
min(d, key=lambda k: d[k][0])
# 'a'
min(d, key=lambda k: d[k][1])
# 'c'

```
Here's a portable method you can use for dicts with a structure like yours, and feel free to choose the index of interest in the tuple:

```
def extract_min_key_by_index(cache, index):
    min_val = float('inf')
    min_key = 0

    for k, v in d.iteritems():
        if v[index] < min_val:
            min_key, min_val = k, v[index]

    return min_key

d = {'a': (3, 5), 'b': (5, 8), 'c': (9, 3)}
INDEX = 0

print extract_min_key_by_index(d, INDEX)

```