![](/img/trans.png)
[英]Compare element 0 of two lists of lists; make new list of lists with items in z[0] that are not in x
[英]Compare elements in two lists and make a new List
通過比較兩個列表的第i個位置,從兩個列表中創建一個新列表。 我可以使用循環來做,但不能使用列表理解
我的代碼:
List1=[1,2,7,8]
List2=[3,4,5,6]
List3=[]
for i in range(len(List1)):
if(List1[i]>List2[i]):
List3.append(List1[i])
else:
List3.append(List2[i])
print(List3)
所需的輸出:[3,4,7,8]
使用郵編:
List3 = [max(x) for x in zip(List1, List2)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.