【发布时间】:2018-10-31 16:34:04
【问题描述】:
我想使用列表推导来更改此函数,以便它具有 1 或 to 行。该函数将包含列表的列表转换为包含元组的元组中的列表
def lol(lista):
novotuplo = ()
for i in range(len(lista)):
novotuplo += (tuple(lista[i]),)
return novotuplo
【问题讨论】:
-
试试
novotuplo = tuple((x,) for x in lista) -
novotuplo = (tuple(lst) for lst in lista) -
请提供输入和预期输出
标签: python python-3.x list tuples