列表列表的元素
我有数字的列表(元组元组?)
[[1,2,3],[4,5,6],[7,8,9]]
我想转换在:
(123,456,789)
我对此代码做的,您能否向我建议一种更好的方法?
listacomb = []
for list in permdue:
for number in list:
numerix += "".join(str(number))
listacomb.append(numerix)
numerix=""
return listacomb
I have a list of list(tuple of tuple?) of number
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
I want to transform in:
(123,456,789)
I did with this code, can you suggest to me a better way to do it?
listacomb = []
for list in permdue:
for number in list:
numerix += "".join(str(number))
listacomb.append(numerix)
numerix=""
return listacomb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以做一个列表理解:
输出:
参考:
You can do a list comprehension:
Output:
References:
这是做到这一点的数学方法。我们可以向后迭代每个子派,并构建所需的数字。
此方法避免了性能惩罚弦解决方案。例如,通过服用
[1,2,3]
和Computing3 + 20 + 100
来获得123来起作用。Here is a math approach to doing this. We can iterate each sublist backwards and build out the desired number.
This approach avoids the performance penalizing string solution. It works, for example, by taking
[1, 2, 3]
and computing3 + 20 + 100
, to obtain 123.可以在没有这样的反转的情况下完成:
输出:
It can be done without reversal like this:
Output: