a=len(i)-1 #len-1 because i used range which goes until n-1
b=len(l)-1
mx=max(a,b)
new_list=[] #new list to store the ordered elements
for n in range(mx): #loop until it reaches the last value of the larger list
if n<=a:
new_list.append(l[n])
elif n<=b:
new_list.append(i[n])
print new_list
您可以使用
zip
:输出:
您可以在两个列表上循环,并按照所需的顺序将其每个元素插入一个新列表中。你知道吗
相关问题 更多 >
编程相关推荐