Question: I have a list of strings (both strings and list can be large). I want to build dictionary out of only certain elements from the list.

```
l = ['aaa 0','bbb 1','ccc 2','ddd 3','abc 1']
wanted = set(['aaa','abc'])
dict([x.split() for x in l if x.split()[0] in wanted])

{'aaa': '0', 'abc': '1'}

```

Can this be done without calling `split()` operation twice?

Answer: 
Using nested generator expression (`(x.split() for x in l)`) to yield key, value pairs:

```
>>> l = ['aaa 0', 'bbb 1', 'ccc 2', 'ddd 3', 'abc 1']
>>> wanted = {'aaa', 'abc'}
>>> {key: value for key, value in (x.split() for x in l) if key in wanted}
{'abc': '1', 'aaa': '0'}

```
I don't know if is more efficient but the following statement uses `split` once:

```
{k: n for k, n in dict([x.split() for x in l]).iteritems() if k in wanted}

```