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!
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00
Over the course of this tutorial series, you’ve become a power user of the Python zip()
function. You’ve learned in great detail how’s zip()
works, how zip()
has changed from Python 2 to Python 3, as well as how to modify your code as needed to deal with those changes.
00:16
You’ve learned how to use the zip()
function for parallel iteration, to create dictionaries and sort iterators on the fly, and then how to combine zip()
with list and dictionary comprehensions to generate really concise, readable output in list and dictionary form.
00:31
I know I’ve had a lot of fun recording this series, and so I hope you’ll get out there and start using zip()
in your own Python code. Thanks for watching!
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.
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?