Using the Python zip() function for Parallel Iteration

Click for: original source

Leodanis Pozo Ramos wrote this tutorial about Python’s zip() function. It creates an iterator that will aggregate elements from two or more iterables. You can use the resulting iterator to quickly and consistently solve common programming problems, like creating dictionaries.

he 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.

Python’s dictionaries are a very useful data structure. Sometimes, you might need to build a dictionary from two different but closely related sequences. A convenient way to achieve this is to use dict() and zip() together.

By the end of this tutorial, you’ll learn:

  • How zip() works in both Python 3 and Python 2
  • How to use the Python zip() function for parallel iteration
  • How to create dictionaries on the fly using zip()

A lot of code examples to demonstrate efficient actions on items in parallel. Nice one!

[Read More]

Tags python programming code-refactoring performance