Python convert list of nested tuples to list of tuples

Nitin

I have a list of nested tuples as

[(('p1', 'p2'), ('m1',)), (('p2', 'p1'), ('m1',))]

How can i convert it into list of tuples as

[('p1', 'p2', 'm1'), ('p2', 'p1', 'm1')]

without using for loop

Rahul K P

You can do with itertools.chain,

In [91]: from itertools import chain
In [92]: [tuple(chain(*item)) for item in a]
Out[92]: [('p1', 'p2', 'm1'), ('p2', 'p1', 'm1')]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python Nested tuples to list

From Dev

Python convert a list of nested tuples into a dict

From Dev

How to convert a two nested list of lists into a nested list of tuples in Python?

From Dev

How to convert nested list of lists into a list of tuples in python 3.3?

From Dev

Convert a list of strings to a list of tuples in python

From Dev

Python convert a list of lists into a list of tuples

From Dev

Convert a list of string into tuples

From Dev

Convert a list of string into tuples

From Dev

how to convert a list of tuples into a lists of part of tuples in python

From Dev

Convert list of tuples in tabular format in python

From Dev

Convert list of tuples of several values into dictionary in Python

From Dev

How to convert a list of tuples to a dictionary of dictionaries in Python?

From Dev

How to convert a list to a list of tuples?

From Dev

Convert List of list into tuple of tuples

From Dev

Convert from tuple of tuples to nested tuples in Python

From Dev

python unpacking list of tuples

From Dev

Ordering a list of tuples in python

From Dev

Merging list of tuples in python

From Dev

Python List of tuples in Scala

From Dev

max in a list of tuples (Python)

From Dev

Merging list of tuples in python

From Dev

comparing a list of tuples python

From Dev

tuples and list arrangements in python

From Dev

Dictionary with list of tuples Python

From Dev

How to unpack tuples in nested list?

From Dev

How to remove tuples nested on a list?

From Dev

How to unpack tuples in nested list?

From Dev

Convert Nested dictionaries to tuples python

From Dev

Swapping tuples in a list of tuples