如何在python中将元组列表转换为元组元组

How to convert list of tuples to tuple of tuples in python

本问题已经有最佳答案,请猛点这里访问。

我正在尝试将元组列表转换为元组列表,我所做的操作是错误的,请帮助解决此问题。

1
2
3
4
5
6
7
list1= [('2', '297'), ('6', '297')]

for x in list1:
    print("inside fn")
    print(x)
    tuple_of_tuples+=tuple(x)
    print(tuple_of_tuples)

输出=('2', '297', '6', '297')。我要输出为(('2', '297'), ('6', '297'))


1
2
3
4
In [1]: list1= [('2', '297'), ('6', '297')]

In [2]: tuple(list1)
Out[2]: (('2', '297'), ('6', '297'))