在python中,将一个元组的每个元素放在另一个元组中

2024-05-08 15:13:26 发布

您现在位置:Python中文网/ 问答频道 /正文

Tuple1=('a','b','c')

Tuple2=(('a',),('b',),('c',))

我想将tuple first Tuple1更改为Tuple2。有简单的方法吗


Tags: 方法firsttupletuple2tuple1
3条回答

我会:

tuple2 = tuple((t,) for t in tuple1)

这里

tiple1=("1",'2','3')
new_tup=tuple(((val,) for val in tiple1))
print(new_tup)

输出:

(('1',), ('2',), ('3',))

尝试:

Tuple2 = tuple([tuple(el) for el in Tuple1])

相关问题 更多 >

    热门问题