我需要执行以下操作:
list1 = [2,4,6,8]
list2 = [2,4,6,8]
我已经尝试做 2 个 for 循环来迭代每个列表然后尝试删除最后一个元素。还没有工作。
#I need to iter them and get combinations as follow:
[2,2]
[2,4]
[2,6]
[2,8] #this would be the largest element
[4,2]
[4,4]
[4,6] #then maximum minus one element
[6,2]
[6,4] #then maximum minus one element
[8,2] #until the first element is the last one
你可以尝试这样的事情:
for i in range(len(list1)):
for j in range(len(list2) - i):
print(list1[i], “,”, list2[j])