You can use the unpacking operator * to print the result of zip() as separate elements.
Here's an example:
fruits = ["apple", "banana", "cherry"]colors = ["red", "yellow", "pink"]zipped = zip(fruits, colors)print(*zipped) |
In this example, we define two lists called fruits and colors, each containing three elements. We then use the zip() function to iterate over both lists in parallel and create a new iterator that yields tuples of corresponding elements.
We store the result of zip() in a variable called zipped, and then use the unpacking operator * to print the tuples as separate elements. This will print the following output:
('apple', 'red') ('banana', 'yellow') ('cherry', 'pink') |
Note that once you've unpacked the zip() iterator using *, it will be exhausted and cannot be reused. If you want to use the zip() iterator multiple times, you should store the result in a list or tuple instead.