-1
A
回答
2
Joachim Isaksson說的是正確的。
這將是有益的,如果你能提供一個代碼片段,但你可以使用這樣的事情:
import itertools
for a, b, c in itertools.izip (list1, list2, list3):
...
0
檢查signature for zip。它接受任何數目iterables的:
拉鍊(* iterables)
是沒有問題的zip
荷蘭國際集團多個列表:
a, b, c = [1,2,3],[4,5,6],[7,8,9]
for (i,j,k) in zip(a,b,c):
print(i,j,k)
打印:
1 4 7
2 5 8
3 6 9
你甚至可以郵編0
或1
次迭代!
list(zip()) # []
list(zip([1,2,3])) # [(1,), (2,), (3,)]
1
zip
可用於任意多個列表。我只是這樣做,它工作正常。
l1 = [1, 2, 3, 4]
l2 = [10, 20, 30, 40]
l3 = [100, 200, 300, 400]
l4 = [1000, 2000, 3000, 4000]
for x1, x2, x3, x4 in zip(l1, l2, l3, l4):
print(x1, x2, x3, x4)
輸出:
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
相關問題
- 1. 的Python for循環遍歷列表
- 2. 循環遍歷Python中的列表
- 3. Python BeautifulSoup - 循環遍歷多個頁面
- 4. Django循環遍歷列表
- 5. 循環遍歷表列
- 6. 循環遍歷python中的多個url請求的值列表
- 7. 循環遍歷兩個XML列表
- 8. python beautifulsoup循環遍歷表格行
- 9. 循環遍歷R中的多列
- 10. 多次循環遍歷DataTable
- 11. xquery循環遍歷列
- 12. MySQL循環遍歷列
- 13. 循環遍歷cf9中的列表
- 14. 循環遍歷遞歸列表C
- 15. 循環遍歷列表向量
- 16. 遍歷錶行的循環
- 17. Angularjs循環遍歷表
- 18. Jquery循環遍歷錶行
- 19. 循環遍歷錶行
- 20. 循環遍歷多個標籤數組
- 21. 遍歷列表(Python)
- 22. 循環遍歷一個NSMutableArray
- 23. 循環遍歷一個NSMutableDictionary
- 24. 循環遍歷Python中的整數列表並返回兩個新列表
- 25. Python,下一個循環遍歷循環迭代
- 26. 循環遍歷LinkedList
- 27. (Python)在嵌套for循環中列表遍歷?
- 28. 用循環遍歷Python,直到到達列表的末尾
- 29. python,遍歷嵌套for循環中的列表
- 30. 如何使用for循環來循環遍歷Python中的嵌套列表
你在哪裏買的'zip'只接受兩份名單? 'A = [1,2,3];列表(zip(a,a,a,a,a))給出了[(1,1,1,1,1),(2,2,2,2,2),(3,3,3, 3,3)]' –
但我已經在循環中嘗試了(zip,gpxd_wpt_coordinates,gpxd_wpt_names,addressListAll)中的(item,name,address):''這裏gpxd_wpt_coordinates,gpxd_wpt_names和addressListAll是列表。我得到的項目和名稱的輸出。但我得到一個錯誤,「addredd沒有定義」 – user8162
我猜'addredd'是一個錯字?無論哪種方式,它看起來應該工作得很好。看到傑伊的回答下面,基本上你想做的事情。 –