Locked learning resources

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

Unlock This Lesson

Locked learning resources

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

Unlock This Lesson

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
Avatar image for DanielHao5

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?

Avatar image for mith1979

mith1979 on June 3, 2020

Nice explanation !!!

Avatar image for Liam Pulsifer

Liam Pulsifer RP Team on June 3, 2020

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

Avatar image for Liam Pulsifer

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.

Avatar image for Alan ODannel

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.

Avatar image for km

km on June 5, 2020

Awesome Series.... ! Thanks a lot

Avatar image for Liam Pulsifer

Liam Pulsifer RP Team on June 5, 2020

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

Avatar image for Sandivya Saxena

Sandivya Saxena on June 6, 2020

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

Avatar image for Carlo Barrientos

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.. :)

Avatar image for Liam Pulsifer

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.

Avatar image for emilbuncianu

emilbuncianu on June 18, 2020

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

Avatar image for Ghani

Ghani on Oct. 20, 2020

Very informative and dense tutorial; many thanks!

Avatar image for shachi

shachi on June 1, 2021

Well explained! Thank you :)

Become a Member to join the conversation.