我有兩個清單。
一個只是一個常規串列,其中元素只是數字,另一個串列是嵌套串列,元素是圖片的 url。
例如,
#a regular list
id=[100, 200, 300, ...]
#a nested list
urls=[['http://www.a.jpg','http://www.b.jpg','http://www.c.jpg'],
['http://www.dd.jpg','http://www.ee.jpg'],
['http://www.fff.jpg','http://www.gggg.jpg','http://www.hhhh.jpg']]
我的目標是使用 for 回圈并為常規串列中的每個元素迭代嵌套串列中的每個元素。例如,當我構建一個遍歷每個 id 的回圈時,我還想列印出嵌套串列中的相應元素。
Expected code for this would be:
for i in id:
#here I need to print out each element from the nested list
...
Expected output:
100, ['http://www.a.jpg','http://www.b.jpg','http://www.c.jpg']
200, ['http://www.dd.jpg','http://www.ee.jpg']
300, ['http://www.fff.jpg','http://www.gggg.jpg','http://www.hhhh.jpg']
用于從 url 保存影像并放入本地計算機的代碼的其他部分幾乎就在那里,但我不斷迭代錯誤的元素或重復項。我花了這么多時間..請有人幫我解決這個問題嗎?
uj5u.com熱心網友回復:
怎么樣(例如在 Python 中)
for i in range(0, len(id)):
print(id[i], "," , urls[i])
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/329907.html
