Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- something_dict = {
- 'a': [1, 2, 3],
- 'b': [4, 5, 6],
- 'c': [7, 8, 9],
- }
- # 1. Initial
- something = sum([zip((k,) * len(v), v) for k, v in something_dict.iteritems()], [])
- print something
- # 2. Explicit variant
- def flatten_dict(d):
- for k, values in d.iteritems():
- for v in values:
- yield k, v
- print list(flatten_dict(something_dict))
- # 3. Itertools variant
- from itertools import product, chain
- print list(chain.from_iterable(product(k, v) for k, v in something_dict.iteritems()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement