Len's slice - zip not returning count?

Hi Guys,

Quick question. In the exercise len’s slice there is a task

Your boss wants you to do some research on $2 slices.
Count the number of occurrences of 2 in the prices list, and store the result in a variable called num_two_dollar_slices . Print it out.

Everything goes well and I get the answered required ,my question is, why does count not return any value for list pizzas?

toppings = ['pepperoni','pineapple','cheese','sausage','olives','anchovies','mushrooms']


prices = [2,6,1,3,2,7,2]

pizzas = list(zip(prices,toppings))
cheapest_pizza = pizzas[1]
priciest_pizza = pizzas[-1]
three_cheapest = pizzas[:3]

print("We sell" ,num_two_dollar_slices , "different kinds of pizza!")

Hello, @tagplayer34457.

Look closely at the use of .count():

Which list is the method called on?

If your question is why does pizzas.count(2) return 0, that’s another matter entirely. .count() is looking for the value specified in the argument you provide. If you print the pizzas list what do you see? Is (2, 'pepperoni') the same value as 2? It would take some work to count the 2's included in the tuples included in the pizzas list. Work that is unnecessary since we have access to the prices list.

For extra practice, you could come up with a way to count the 2's in the pizzas list.

1 Like