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.
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.
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
.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.
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.
Hi there,
my feeling is, that the gradebook as well as the Len’s slice project are not updated yet. I got pretty much stuck in these projects since I wasn’t able to come up with a solution based on the previous learnings. Would be great, if you could be more precise with the task there.
However, a solution I found is at least not as unsexy as writing the whole 2d list manually and is pretty close to the learnings at this stage of the course so far:
Hello! I am assuming you were stuck on step 6: “Convert our toppings and prices lists into a two-dimensional list called pizza_and_prices that has the following associated values.”
Can you clarify what is confusing about step 6? Is it the usage of “convert” that is implying you need to use something like zip() or list()?
Would saying something like “Use the existing toppings and prices information to form a two-dimensional list” clarify this issue?
Hi!
Yep, I guess “convert” triggered me. Your phrase suggestion is already much better, but I would be even more precise. Since the manual creation of the new list does not gain any learnings, I would explicitly say, that this list has to be created manually. Even better would perhaps be, if you would provide the list as you did with some other part of the code in the exercises before. Part of this exercise must then be, that you have to “uncomment” the list to use it in the further tasks.
Thanks for picking this topic up again!
Hello I typed the second list but I am still getting an error
This is my code
num_two_dollar_slices = prices.count(2)
print(num_two_dollar_slices)
num_pizzas = len(list(toppings))
print(‘We sell’, num_pizzas, ‘kinds of pizza’)
pizza_and_prices = [[2, ‘pepperoni’], [6, ‘pineapple’], [1, ‘cheese’], [3, ‘sausage’], [2, ‘olives’], [7, ‘anchovies’, [2, ‘mushrooms’]]
I get a syntax error here and so cannot continue. Thank you!