我有清单清单。让我们这样说:
somelist = [
[1, 2, 3],
[4, 8, 2],
[7, 8, 4, 8, 2],
]
这里我的列表包含 3 个列表。使用列表len(list) == 3
我想做这样的事情:
list1 = somelist[0]
list2 = somelist[1]
list3 = somelist[2]
for l1 in list1:
for l2 in list2:
for l3 in list3:
function(something=[l1, l2, l3])
但我的清单可以有2 <= len(somelist) <= 10
。所以如果我的清单有len(somelist) == 4
我必须做的:
list1 = somelist[0]
list2 = somelist[1]
list3 = somelist[2]
list4 = somelist[3]
for l1 in list1:
for l2 in list2:
for l3 in list3:
for l4 in list4:
function(something=[l1, l2, l3, l4])
所以我的问题是如何编写适用于不同的漂亮代码len(somelist)
?