2 回答

TA贡献1993条经验 获得超5个赞
您可以在 url 和文件名之间创建映射 (dict),然后遍历字典。
另一种方法是zip两个列表并迭代结果。
另一种方法是枚举 url 并根据索引获取文件名。
第一个选项假设在download_url_lists 最后两个假设中没有重复项download_url_lists并且image_list具有相同的大小。
info = zip(download_url_lists, image_list)
for url, filename in info:
...
# or
mapping = dict(info)
for url, filename in mapping.iteritems():
...
# or
for index, url in enumerate(download_url_lists):
filename = image_list[index]
...

TA贡献1799条经验 获得超6个赞
您可以使用在每次迭代中都会发生变化的变量;
看到这个:-
>>> list1 = [ 'a', 'b', 'c', 'd' ]
>>>
>>> var, list2 = 0, []
>>> for i in list1:
... filename = 'file{}'.format(var)
... var += 1
... list2.append(filename)
...
>>> list2
['file0', 'file1', 'file2', 'file3']
添加回答
举报