Question: I have two dictionaries,i want to combine these two int a list in the format keys-->values,keys-->values... remove any None or ['']

currently I have the below where I can combine the dicts but not create a combined lists...i have the expecte output..
any inputs appreeciated

```
dict1={'313115': ['313113'], '311957': None}
dict2={'253036': [''], '305403': [], '12345': ['']}

dict = dict(dict1.items() + dict2.items())
print dict

{'313115': ['313113'], '311957': None, '253036': [''], '12345': [''], '305403': []}

EXPECTED OUTPUT:
['313115','313113','311957','253036','305403','12345']

```

Answer: 
This should do it:

```
[i for k, v in (dict1.items() + dict2.items()) for i in [k] + (v or []) if i]

```

walk the combined items of the two dicts, then walk the key plus the list of values, returning each item from the second walk that exists.

Returns `['313115', '313113', '311957', '253036', '12345', '305403']` on your example dicts -- the order is different because python's dict iteration is unordered.

EDIT:

`dict.items()` can be expensive on large dicts -- it takes O(n) size, rather than iterating. If you use itertools, this is more efficient (and keeps the dicts you're working with in one place):

```
import itertools
[i
 for k, v in itertools.chain.from_iterable(d.iteritems() for d in (dict1, dict2))
 for i in [k] + (v or [])
 if i]

```

Thanks to Martijn Pieters for the from\_iterable tip.
```
[each
 if isinstance(each,  str) else each[0]
 for pair in dict(dict1, **dict2).iteritems()
 for each in pair
 if each not in [[''], None, []]]

```