[英]Python: Removing tuples from a list of lists
I have a list of lists containing tuples:我有一个包含元组的列表:
[[(1L,)], [(2L,)], [(3L,)], [(4L,)], [(5L,)]
how do i edit the list so the list looks like:我如何编辑列表,使列表看起来像:
l = [[1][2][3][4][5]]
>>> a
[[(1L,)], [(2L,)], [(3L,)], [(4L,)], [(5L,)]]
>>> a = [[x[0][0]] for x in a]
>>> a
[[1L], [2L], [3L], [4L], [5L]]
if you have, for instance, two items in each sub-list you would need something like this例如,如果您在每个子列表中有两个项目,您将需要这样的东西
example_list = [[(1, 0)], [(1, 1)], [(1, 3)], [(1, 4)], [(1, 5)]]
example_list = [[x[0][0], x[0][1]] for x in example_list]
print(example_list)
Output: [[1, 0], [1, 2], [1, 3], [1, 4], [1, 5]]
输出:
[[1, 0], [1, 2], [1, 3], [1, 4], [1, 5]]
(note: this is using Python 3.8) (注意:这是使用 Python 3.8)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.