FAQ: List Comprehension - Divide With Zip

This community-built FAQ covers the “Divide With Zip” exercise from the lesson “List Comprehension”.

Paths and Courses
This exercise can be found in the following Codecademy content:
Analyze data with Python

FAQs on the exercise Divide With Zip

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

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!

Hi, can someone show an example of what they mean by Divide With Zip?
I don’t understand how to use math functions with the Zip command. Thanks.
Here’s the link to the question:

https://www.codecademy.com/paths/analyze-data-with-python/tracks/ida-2-introduction-to-python/modules/ida-2-4-list-comprehension/lessons/lists/exercises/zip-divide

Divide and zip are separate concepts
divide is a function taking in two arguments and returning one value
if you have two lists, you can iterate through them in sync

for a, b in zip(list_of_as, list_of_bs):
    print(a, b)

map also already has this pairing/grouping behaviour built in:

from operator import div
a = [1.0, 2.0, 3.0]
b = [4.0, 5.0, 6.0]
map(div, a, b)  # 0.25 0.4 0.5
1 Like

Hello, there are some issues with accepting correct answers. Already reported a bug.

The code:

a = [1.0, 2.0, 3.0]
b = [4.0, 5.0, 6.0]

quotients = [b / a for (a, b) in zip(a, b)]
print(quotients)

The program doesn’t accept it, but outputs the correct “print()” statement.
Also shows: “zip argument #1 must support iteration”.
And, at the previous exercise-challenge with summation, everything was ok with this style of coding.

Thank you.

Its best not to get mixed up with the original lists therefore assign it as a different list of each

Here is the solution:

a = [1.0, 2.0, 3.0]
b = [4.0, 5.0, 6.0]

quotients = [l1 / l2 for (l1, l2) in zip(b, a)]

print(quotients)
2 Likes

My code:

a = [1.0, 2.0, 3.0]
b = [4.0, 5.0, 6.0]
quotients = [num1 / num2 for (num1, num2) in zip(b, a)]

But the solution was

a = [1.0, 2.0, 3.0]
b = [4.0, 5.0, 6.0]
quotients = [item2 / item1 for (item1, item2) in zip(a, b)]

Mine works, but I do not know if I was following best practices because the solution given is different.