Len's lists

toppings = [“pepperoni”, “pineapple”, “cheese”, “sausage”, “olives”, “anchovies”, “mushrooms”]
print(toppings)

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

print(prices)

num_two_dollar_slices = prices.count(2)
print(num_two_dollar_slices)

num_pizzas = len(toppings)
print(num_pizzas)
str(num_pizzas)
print(" we sell " + str(num_pizzas) + " different kinds of of pizza!")

pizzas_and_prices = [[2,“pepperoni”] + [6, “pineapple”] + [1, ‘cheese’] + [3, ‘sausage’] + [2, ‘olives’] + [7, “anchovies”] + [2, ‘mushrooms’]]
print(pizzas_and_prices)

print(pizzas_and_prices)

pizzas_and_prices.sort()

print(pizzas_and_prices.sort

Ok so the above code is where Im at on the “len’s list exercise”, when I sort this, by default according to the lessons it should go into ascending order. however thats not whats happening here. When I use the print function, its spitting the information out in the same order in which the sub lists were entered. newlist = .sorted(list) does the exact same thing

Anyone can give a tip ?

Hi,
Your problem is on this line;

pizzas_and_prices = [[2,“pepperoni”] + [6, “pineapple”] + [1, ‘cheese’] + ... 

Using, + , you’re essentially creating a list of one big single item - and hence sorting it doesn’t change anything.

Swap the + for , (commas) and you should be ok.

lst = [[1,“one”] , [2, “two”] , [3, “three”] , …]

hope that helps

It’s also a good idea to understand the differences between .sort() and sorted() for this lesson.

https://docs.python.org/3/howto/sorting.html