[英]convert list to sequence of tuples
Is there anyway to convert 无论如何转换
A = [((0,0,0),), ((1,1,1),), ((2,2,2),) ]
to this 对此
B = ((0,0,0),), ((1,1,1),), ((2,2,2),)
In other words, all I want to do is remove the end brackets so that I can input B into a certain argument. 换句话说,我想要做的就是删除结束括号,以便我可以将B输入到某个参数中。 I do not want any outer parentheses/brackets/quotations on B
我不希望B上有任何外括号/括号/引号
Any help would be appreciated. 任何帮助,将不胜感激。 Thanks
谢谢
If you are passing A
as an argument to a function fn(A1, A2, A3)
, you can pass the elements of A
individually as follows: 如果将
A
作为参数传递给函数fn(A1, A2, A3)
,则可以单独传递A
的元素,如下所示:
fn( *A )
The *
operation on a list/tuple when passed to a function unpacks the elements in the list/tuple. 传递给函数时列表/元组上的
*
操作解包列表/元组中的元素。
假设你想要一个字符串表示:
B = ", ".join(repr(t) for t in A)
A quick and dirty way to do it would be to do something like this: 快速而肮脏的方法是做这样的事情:
B = A[0], A[1], A[2]
Which results in 结果如何
(((0, 0, 0),), ((1, 1, 1),), ((2, 2, 2),))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.