可以使用下面的代码实现:
nested_list =[ [1, 2, 3], [4, 5, 6, 7], [8, 9], [10, 11, 12, 13, 14] ]
for i, sublist in enumerate(nested_list):
nested_list[i] = [len(sublist)] + sublist
print(nested_list)
该代码遍历嵌套列表中的每个子列表,并使用列表的长度作为编号替换原来的子列表。
可以使用下面的代码实现:
nested_list =[ [1, 2, 3], [4, 5, 6, 7], [8, 9], [10, 11, 12, 13, 14] ]
for i, sublist in enumerate(nested_list):
nested_list[i] = [len(sublist)] + sublist
print(nested_list)
该代码遍历嵌套列表中的每个子列表,并使用列表的长度作为编号替换原来的子列表。