Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Parallel Iteration With Python's zip() Function (Summary)

In this course, you’ve learned how to use Python’s zip() function. zip() can receive multiple iterables as input. It returns an iterator that can generate tuples with paired elements from each argument. The resulting iterator can be quite useful when you need to process multiple iterables in a single loop and perform some actions on their items at the same time.

Now you can:

  • Use the zip() function in both Python 3 and Python 2
  • Loop over multiple iterables and perform different actions on their items in parallel
  • Create and update dictionaries on the fly by zipping two input iterables together

You’ve also coded a few examples that you can use as a starting point for implementing your own solutions using Python’s zip() function. Feel free to modify these examples as you explore zip() in depth!

Download

Course Slides (.pdf)

297.6 KB
Download

Sample Code (.py)

2.1 KB

DanielHao5 on June 2, 2020

Good intro to this powerful built-in function. All the examples are very well crafted and have practical use cases.

Thank you.

BTW - what’s the IDLE in the presentation?

mith1979 on June 3, 2020

Nice explanation !!!

Liam Pulsifer RP Team on June 3, 2020

Thanks for the comment @mith1979, glad you enjoyed the course!

Liam Pulsifer RP Team on June 3, 2020

Thanks for watching, @DanielHao5! Glad you enjoyed the course and the examples. The REPL I use in these tutorials is PtPython, which is available through Pip.

Alan ODannel on June 4, 2020

Very good course. I haven’t taken the opportunity to learn how Zip works. This course gave me the desire to dig into Zip.

km on June 5, 2020

Awesome Series.... ! Thanks a lot

Liam Pulsifer RP Team on June 5, 2020

Thanks for the kind comments @Alan O’Dannel and @km! Glad you enjoyed the series.

Sandivya Saxena on June 6, 2020

Just subscribed to RealPython, in this first course itself, learned atleast 3 new things. KUDOS!

Carlo Barrientos on June 12, 2020

Liam, This is clear and applicable immediately; The examples are excellent for getting the points across without being confusing. I had seen zip used in code before but mostly for building dictionaries. I think its interesting that I’d never seen it used for its primary use of processing more than 2 lists in parallel. I found my mind wandering during the discussion of python 2 in 2nd section ; you might want to split out the python 2 discussion and give students the opportunity to ‘skip’ the python 2 discussions if they are “done with python 2.7” and never want to deal with it again.. :)

Liam Pulsifer RP Team on June 15, 2020

Thanks for the comment @Sandivya Saxena, glad you found this useful :)

Thanks @Carlo Barrientos for the thoughtful comment! I’ll keep that in mind for future tutorials involving Python 2.

emilbuncianu on June 18, 2020

This course is well explained! I understood everything even if I used Zip for first time in this tutorial.

Ghani on Oct. 20, 2020

Very informative and dense tutorial; many thanks!

shachi on June 1, 2021

Well explained! Thank you :)

Become a Member to join the conversation.