Sort function not worknig

Hi @Paul_Maxwell, welcome to Jupyter :tada:. Jupyter is a project enabling interactive computing using a variety of languages (including Julia, Python, R, and many others); you did not specify the language you are using and it might be difficult for volunteers like me to help you without knowing it. You would normally know what language you are using, but if you are using a Jupyter notebook on a platform provided by someone else (e.g. University) you can easily check it by looking at the right-top corner. I highlighted in blue how it looks like in JupyterLab:

And in Jupyter Notebook:

I am going to take a bet and assume that you are using Python; in that case a likely reason would be the use of the round parentheses ( and ) instead of square brackets [ and ] as the former defines a tuple, while the latter defines a list. In Python tuples and lists are similar, but while lists can be changed (e.g. can be extended with an extra element, or rearranged), tuples always stay the same after creation (are immutable). This is why there is list.sort but no tuple.sort.

The good news is that having a Python variable you can always check its type yourself, for example:

object_from_question = (200, 60, 7, 190, 89, 3, 20, 0)
type(object_from_question)

Will return:

tuple

while:

my_list = [200, 60, 7, 190, 89, 3, 20, 0]
type(my_list)

Will give you:

list

And just to show that sorting works well on lists:

my_list.sort()
my_list

[0, 3, 7, 20, 60, 89, 190, 200]

Also here is the same as a screenshot:

If you are new to programming with Python you can safely assume that in 99% of cases the issue will be related to the programming language rather than to the Jupyter interface. It is just an intermediary between you and the language of your choice, and usually a good one :).

2 Likes