FAQ: Creating and Modifying a List in Python - Zip


#1

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!


#2

I’ve just been introduced to Zip (lesson 4 of Lists) and basically I can’t seem to get past the first instruction. The output I have is correct, as in it’s paired the two separate lists together into a a zip object which is then viewed by: print(list(names_and_dogs_names))

But I get an error message saying: " Is names_and_dogs_names a zip() with names first and dogs_names second?"

This is rather annoying because my printed output is correct, yet CodeAcademy compiler or whatever it is that checks that the condition for the instruction has bee met, has simply not worked. Unless there is something blatantly obvious I’ve missed out on. The full code is below:

names = [‘Jenny’, ‘Alexus’, ‘Sam’, ‘Grace’]
dogs_names = [‘Elphonse’, ‘Dr. Doggy DDS’, ‘Carter’, ‘Ralph’]
#List of Lists
names_and_dogs_names = zip(names, dogs_names)
print(list(names_and_dogs_names))


#3

Go back and carefully read and follow step two.


#4

So, it now works. I’m guessing because I just wrote this:

names_and_dogs_names = zip(names, dogs_names)

Wait… I’m an idiot. I just realized it. It’s because I hadn’t assigned the zip object to a list yet. And so my print statement wouldn’t have worked and I didn’t read the instruction properly. Which was basically just Run the code when you’ve created zip object, then follow onto instruction 2.

I’ve also came to learn that I can create a list and zip the object in one line like so:

names_and_dogs_names = list(zip(names, dogs_names))

It’s not needed for this exercise, but it was good for me to find out you can do this. Thanks for the help mtf!