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: 
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}

```
You can reduce the split() operation to one. 

```
l = ['aaa 0','bdb 1','ccc 2','ddd 3','abc 1']
dict = { }
s = set(['aaa','abc'])
for elem in l:
    nl = elem.split()
    if nl[0] in s:
        dict[nl[0]] = nl[1]
for elm in dict:
    print elm,dict[elm]

```