Question: This question is a part of my current problem, so let's start with the big picture.

I am trying to sort a dictionary by the values in descending order. My dictionary is 1-to-1 corresponding, such as:

> 
> ('ID1':value1, 'ID2':value2, ......)
> 
> 
> 

I followed [this thread](https://stackoverflow.com/questions/613183/python-sort-a-dictionary-by-value) and find my answer:

```
import operator
sorted_dict = sorted(original_dict.iteritems(), key = operator.itemgetter(1), reverse = True)

```

Then I tried to extract the keys in `sorted_dict` since I thought it is a `dictionary`. However, it turns out that `sorted_dict` is a `list`, thus has no `keys()` method.

In fact, the `sorted_dict` is organized as:

> 
> [('ID1', value1), ('ID2', value2), .....] # a list composed of tuples
> 
> 
> 

But what I need is a list of ids such as:

> 
> ['ID1', 'ID2', ......]
> 
> 
> 

So now, the problem turns to **How to extract variable in specific position for each of the tuples in a list?**

Any suggestions? Thanks.

Answer: 
You can do that using [list comprehension](http://www.secnetix.de/olli/Python/list_comprehensions.hawk) as follows:

```
>>> ids = [element[0] for element in sorted_dict]
>>> print ids
['ID1', 'ID2', 'ID3', ...]

```

This gets the first element of each `tuple` in the `sorted_dict` list of tuples
Use `map` plus `itemgetter` to process a list and get the first element

```
import operator
first_elements = map(operator.itemgetter(0), sorted_list)

```