Convert dict of nested lists to list of tuples

Viewed 1383

I have dict of nested lists:

d = {'a': [[('a1', 1, 1), ('a2', 1, 2)]], 'b': [[('b1', 2, 1), ('b2', 2, 2)]]}
print (d)
{'b': [[('b1', 2, 1), ('b2', 2, 2)]], 'a': [[('a1', 1, 1), ('a2', 1, 2)]]}

I need create list of tuples like:

[('b', 'b1', 2, 1), ('b', 'b2', 2, 2), ('a', 'a1', 1, 1), ('a', 'a2', 1, 2)]

I tried:

a = [[(k, *y) for y in v[0]] for k,v in d.items()]
a = [item for sublist in a for item in sublist]

I think my solution is a bit over-complicated. Is there some better, more pythonic, maybe one line solution?

1 Answers
Related