Python 如何将内部元素元组更改为列表?

Python 如何将内部元素元组更改为列表?,python,Python,我想将x中的内部元组元素更改为list,也就是说,将x更改为 >>> x=[[(1,2,3),(10,9,8)]] >>> x [[(1, 2, 3), (10, 9, 8)]] >>> 我该怎么做? 如何使用for循环而不是列表理解获得它 [[[1, 2, 3], [10, 9, 8]]] 使用列表理解,如下所示 for unit in x: for cell in unit: cell=list(cell)

我想将x中的内部元组元素更改为list,也就是说,将x更改为

>>> x=[[(1,2,3),(10,9,8)]]
>>> x
[[(1, 2, 3), (10, 9, 8)]]
>>>
我该怎么做? 如何使用for循环而不是列表理解获得它

[[[1, 2, 3], [10, 9, 8]]]

使用列表理解,如下所示

for unit in x:
    for cell in unit:
        cell=list(cell)
这类似于

x = [[(1, 2, 3), (10, 9, 8)]]
print [[list(item) for item in items] for items in x]
# [[[1, 2, 3], [10, 9, 8]]]

@将新对象分配给循环中的
单元格
不会改变单元格引用的实际对象。
result = []
for items in x:
    temp = []
    for item in items:
        temp.append(list(item))
    result.append(temp)
print result
# [[[1, 2, 3], [10, 9, 8]]]