Use the print() function with a list() class to convert the zip object (iterator) to a list and print in Python. To print a zipped list:
- Use the
zip()
function to get an iterator of tuples. - Use the
list()
class to convert the iterator to a list. - Use the
print()
function to print the list.
Print zip object Python
Simple example code.
list_1 = [1, 2, 3]
list_2 = ['X', 'Y', 'Z']
my_list = list(zip(list_1, list_2))
print(my_list)
Output:
Python range() and zip() object type
In Python 3.x., range
returns a range object instead of a list like in Python 2.x. Similarly, zip
now returns a zip object instead of a list.
range(10)
range(0, 10)
print(list(range(10)))
print(zip('abc', 'abc'))
print(list(zip('abc', 'abc')))
Output:
Comment if you have any doubts or suggestions on this Python zip topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.