Question: I have a `list` of repeating `dict`. I want to filter out a few elements of each `dict`. I can do this by looping through the entire `list`, and select the wanted elements, as shown in the below example. However, this doesn't seem like an efficient method. What is the best way of achieving the desired result, as outputted below, in terms of memory usage and speed?

```
listOfDic = [
      {'firstElement': 'a', 'secondElement': '1', 'thirdElement': 'i'}
    , {'firstElement': 'b', 'secondElement': '2', 'thirdElement': 'ii'}
    , {'firstElement': 'c', 'secondElement': '3', 'thirdElement': 'iii'}
]
filteredListOfDic = []

# looping through old list, selecting first and third element
# and using those elements for building a new "filtered" list of dict
for row in listOfDic:
    filteredListOfDic.append({
          'firstElement': row['firstElement']
        , 'thirdElement': row['thirdElement']
    })

print filteredListOfDic

```

The result being:

```
[{'thirdElement': 'i', 'firstElement': 'a'}
, {'thirdElement': 'ii', 'firstElement': 'b'}
, {'thirdElement': 'iii', 'firstElement': 'c'}]

```

Answer: 
I guess a simple `del` would be enough to delete the elements from each dictionary, instead of copying the desired elements.

```
for l in listOfDic:
    del l["secondElement"]

>>> print listOfDic
>>> [{'thirdElement': 'i', 'firstElement': 'a'}, {'thirdElement': 'ii', 'firstElement': 'b'}, {'thirdElement': 'iii', 'firstElement': 'c'}]

```
If you need to keep your dictionaries, you can create a new one using simple list comprehension:

```
filteredListOfDic = [{"firstElement": row["firstElement"], "thirdElement": row['thirdElement']} for row in listOfDic]

```

**EDIT:** For those suspicious of performance gain when using list comprehension:

```
#time: original_method() - 1,000,000 loops: 1.10493s
#time: lst_comp_method() - 1,000,000 loops: 0.79917s

```

That's almost 40% faster.