.sort method returning none

Hi, I am trying to sort this simple list but the outcome keeps in None, any ideas of why is this happening?

[/codebyte]

Your code below:

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

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

num_two_dollar_slices = 3

num_pizzas = len(toppings)

#print(num_pizzas)

print("We sell “+ str(num_pizzas)+ " different kinds of pizza!”)

pizza_and_prices =

pizza_and_prices = [list(t) for t in zip(prices, toppings)]

print(pizza_and_prices)

print(pizza_and_prices.sort())

.sort() modifies the list in place so it will return “None”.

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

Also,

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

pizza_and_prices.sort()
print(pizza_and_prices)


Output:
[[2, 'pepperoni'], [6, 'pineapple'], [1, 'cheese'], [3, 'sausage'], [2, 'olives'], [7, 'anchovies'], [2, 'mushrooms']]
[[1, 'cheese'], [2, 'mushrooms'], [2, 'olives'], [2, 'pepperoni'], [3, 'sausage'], [6, 'pineapple'], [7, 'anchovies']]
1 Like

oh got it, thought I had to store it in a variable in oder to work with the sorted one, thanks!

1 Like