How to Print a Zipped List in Python?

Estimated read time 2 min read

To print a zipped list in Python, you can use a for loop to iterate over the zipped list and print each item. Here’s an example code snippet that shows how to print a zipped list:

# Define two lists
names = ['Alice', 'Bob', 'Charlie']
ages = [25, 30, 35]

# Zip the two lists together
zipped = zip(names, ages)

# Print the zipped list
for item in zipped:
    print(item)

In this example, the names list contains three strings, and the ages list contains three integers. The zip() function is used to combine the two lists into a single zipped list, where each item is a tuple containing a name and an age. The resulting zipped list is stored in the zipped variable.

To print the zipped list, a for loop is used to iterate over each item in the zipped list. The print() function is called inside the loop to print each item on a separate line. The output will be:

('Alice', 25)
('Bob', 30)
('Charlie', 35)

Note that each item in the zipped list is a tuple containing a name and an age, and the print() function prints each tuple on a separate line. If you want to print the items in a different format, you can modify the print() function inside the loop to print the items in the desired format.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply