[Question]Learn Python 3 - Lists - Len's Slice

Hi everyone, I am doing Len’s Slice practice and I am coming across a difficulty, please see the screenshot below:

The result is expected to be: [[2, ‘pepperoni’], [6, ‘pineapple’], [1, ‘cheese’], [3, ‘sausage’], [2, ‘olives’], [7, ‘anchovies’], [2, ‘mushrooms’]]
But I got: [(2, ‘pepperoni’), (6, ‘pineapple’), (1, ‘cheese’), (3, ‘sausage’), (2, ‘olives’), (7, ‘anchovies’), (2, ‘mushrooms’)]

I do not understand how to get that result. Please help. Thanks in advance!

Link: https://www.codecademy.com/courses/learn-python-3/projects/python-lens-slice

Welcome to the forums :slight_smile:

Using list(zip(a, b)) returns a list of tuples (which are immutable lists) which is why you are getting this output.

At this point in the course though I doubt they want you to hard code everything, and since zip() returns this way I’m not sure how they want you to get a list of lists.

Not that it’s impossible, as you can use list comprehension to do it:

[list(a) for a in zip(prices, toppings)]

But I don’t believe they’ve covered this yet. I’ll ask about it, perhaps there’s a typo in the hint.

3 Likes

I think this and a few other lessons removed any introduction of tuples in a recent update (last couple of weeks), which I suppose is fine, but it broke or confused a few instructions in older lessons. There’s a bug report about it (for a specific lesson). May be worth tagging this instruction in with that group so that it’s made clearer too if the lessons are updated again (fingers crossed).

* Looks like list comps are covered in this course before this project, not sure about zip though or a more advanced comprehension like that one.

3 Likes

I actually do think they expect learners to make the 2D list by hand for this one. The hint suggests they don’t want you to use zip() since this doesn’t involve tuples (and zip has been moved to the end of the Lists module). I don’t think list comprehension is covered yet here, and even for loops aren’t.

My only other guess is that maybe they want learners to build it using .append() (which has been covered):

pizza_and_prices = []
pizza_and_prices.append([2, "pepperoni"])
...
# continue using .append() for each price/topping
2 Likes

I think it’s combining them by hand too.

.zip() is now taught after this project. (we had the same issue with the “gradebook” project after they revamped it too where we’d used .list(zip()) previously.

using .append() repeatedly is tedious. lol.

3 Likes

Yeah, the rationale in moving zip() was to place it after the tuples video and also expand the 2D list content. See this discussion on Discord.

It’s tedious, but the more I think about it, the more I’m inclined to say the curriculum team wants learners to use .append(). Otherwise, what would be the point of printing it out? If you write it by hand, it will look the same printed out as it does in script.py.

2 Likes

I understand it. They just need better copyeditors for the lessons. :wink:

2 Likes

Hi! Curriculum Dev here!

To clarify your question – we are expecting you to manually type out a 2d list here. Our new structure for the project does not need the use of zip().

Sadly, Python does not give us an easy way to form 2d lists without the use of loops (which learners may or may not have learned before this point).

We will take a look at the project to clarify this point for current and future learners. :slight_smile:

4 Likes