Len's Slice sort issue

Hi,

Could you please anyone take a look why I can’t get sorted version table ?

it comes out as None.

Please answer for me.

Thanks,

jinny

See Sorting HOW TO — Python 3.9.5 documentation
It says:


... It modifies the list in-place (and returns `None` to avoid confusion)

You’re printing the return result of calling .sort() method. This method will do the sort on your list directly and always return None.

sorry, I can’t get what you are saying…

I still don’t know

In your code, you already execute the sort() in line 27. So in line 28, you simply print the variable.


pizza_and_prices.sort()   # line 27
print(pizza_and_prices)   # line 28

Does this print the sorted pizza_and_prices?

oh thank you !!! so i dont need to add sort() in print

That’s right. When you execute pizza_and_prices.sort(), it will arrange and order the elements within. Meaning, it’s already done! Hence, no need to call again in the print().
Unlike some other method or function such as the following, they return something:

prices.count(2)
len(toppings)

The .sort() method returns nothing (None), as I mentioned earlier. So, when you attempt to print, that’s the reason you see it prints None. :slightly_smiling_face: