Reputation: 77
I have a list in the following format:
[(('ABC','DEF'),2), (('GHI','JKL'), 4) ...]
I would like to break down to:
[('ABC','DEF', 2), ('GHI','JKL', 4) ...]
Any suggestions?
Upvotes: 2
Views: 45
Reputation: 34166
You can do that with a simple list comprehension:
L = [(('ABC', 'DEF'), 2), (('GHI', 'JKL'), 4)]
new_list = [e[0] + (e[1],) for e in L]
Demo:
>>> print new_list
[('ABC', 'DEF', 2), ('GHI', 'JKL', 4)]
Note: e[0]
is a tuple and e[1]
is an integer. The part (e[1],)
will create a tuple with one element.
Upvotes: 2