python - how to change the inner element tuple into list? -
>>> x=[[(1,2,3),(10,9,8)]] >>> x [[(1, 2, 3), (10, 9, 8)]] >>> i want change inner tuple element in x list ,that ,change x into
[[[1, 2, 3], [10, 9, 8]]] how can ? how can loop not list comprehension?
for unit in x: cell in unit: cell=list(cell)
use list comprehension, this
x = [[(1, 2, 3), (10, 9, 8)]] print [[list(item) item in items] items in x] # [[[1, 2, 3], [10, 9, 8]]] this similar to
result = [] items in x: temp = [] item in items: temp.append(list(item)) result.append(temp) print result # [[[1, 2, 3], [10, 9, 8]]]
Comments
Post a Comment