Geek Culture
Published in

Geek Culture

Looping over two lists with zip

A Pythonistic technique to avoid loop counters

We sometimes need to loop over two different sequences at the same time. For example, if we had two lists:

colors = ["red", "green", "blue"]
shapes = ["circle", "square", "triangle"]

and we wanted to print these lists side by side:

red circle
green square
blue triangle

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Martin McBride

Martin McBride

Software developer. Java, Python, C++ etc. I write for pythoninformer.com and maintain the generativepy library.