FAQ: Creating and Modifying a List in Python - Zip

This community-built FAQ covers the “Zip” exercise from the lesson “Creating and Modifying a List in Python”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Zip

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

3 posts were split to a new topic: Why isn’t the zip printing?

2 posts were merged into an existing topic: Why isn’t the zipped list printing?

6 posts were merged into an existing topic: Why isn’t the zipped list printing?

3 posts were split to a new topic: My code doesn’t work?

2 posts were split to a new topic: What are the differences between zip creating a list of lists or tuples?

3 posts were split to a new topic: Why do I need to set the zipped list as a variable?

Hey guys, two questions – first and foremost, why do zipped, nested lists display with parentheses instead of brackets, given that brackets are the signifiers for lists? Is it to avoid syntax errors? That is, why does

some_list = ["Terry", "Joanne", "Mark"] another_list = [12, 46, 28] zipped_list = zip(some_list, another_list) print(list(zipped_list))

Produce:
[('Terry', 12), ('Joanne', 46), ('Mark', 28)]

Instead of:
[['Terry', 12], ['Joanne', 46], ['Mark', 28]]

Second question is, why wouldn’t you always assign the variable as a list object? That is:

some_list = ["Terry", "Joanne", "Mark"] another_list = [12, 46, 28] zipped_list = list(zip(some_list, another_list)) print(zipped_list)
Is there some utility I’m not aware of to saving a variable as that positional object rather than the list type?

Thanks all!

Because they are not lists, they tuples (which are immutable lists).

zip() is an iterator, here is the official docs:

Iterator - Python Wiki

otherwise google: python iterator, that might result in less in-depth simpler articles :wink:

1 Like

Why does it say to make another variable to change it into a list instead of just doing this:
names_and_dogs_names = list(zip(names, dogs_names))

It seems more simple and efficient to do that instead of making a whole new variable, list_of_names_and_dogs_names.

Likely it is more so that learners can see all the moving parts and how they are transformed from one thing to another. It isn’t necessary at this point to be concerned over efficiency. That comes later. The main concern here is learning the basics and how built-in functions behave and their correct usage and syntax.

Hi, there.
I found a question here when im tring to print (list_of_names_and_dogs_names) after print(list(names_and_dogs_names)).
The output is . No any values.
Cheers