我有这样一个嵌套列表:
l = [['40', '20', '10', '30'], ['20', '20', '20', '20', '20', '30', '20'], ['30', '20', '30', '50', '10', '30', '20', '20', '20'], ['100', '100'], ['100', '100', '100', '100', '100'], ['100', '100', '100', '100']]
我想将l
中的每个元素转换为float
。我有这样的代码:
newList = []
for x in l:
for y in x:
newList.append(float(y))
如何用嵌套的列表理解来解决这个问题?