Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top