Omar Mowafi
Omar Mowafi

Reputation: 854

How to iterate over several list at the same time?

I have a bit of a riddle here what i want to do is have a "for in" which loops on 3 variables from request.POST and request.FILES what i did is:

images = request.FILES.getlist('image')
titles = request.POST.getlist('title')
captions = request.POST.getlist('caption')
for image,title,caption in images,titles,captions:

that doesn't seem to work any solutions?

Upvotes: 3

Views: 196

Answers (1)

Acorn
Acorn

Reputation: 50527

for image, title, caption in zip(images, titles, captions):

..is what you want. (zip docs)

Upvotes: 17

Related Questions