我有列表的列表。讓我們說somethink這樣的:此問題的智能語法
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)
工作?