Sort function not worknig

Hi i am still very new to Jupyter notebook. i do hope someone can help me?
when i create a list list=(200,60,7,190,89,3,20,0) but when i use the sort function list.sort() juypter notebook says thsort ahs no attribute

1 Like

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

Hi T [krassowski thank you i will try that… once again thank you

1 Like

Thank you very much for your reply. could you point me to a useful learning site for Python using the Huypter notebook. i must still be doing something wrong the sort function works sometimes and sometimes i get **(has no objector has no attribute). any help would be very much

using the sort function i am getting this reply *the object needs an argument
cheers for now Paul

There are a lot of many good resources to learn python on the internet. I suggest you read some articles like this and find out what suits you best learning the language. As a start, read some books (like the one written by John Zelle, which I read at first). Here’s another link which can help you to find what you need (scroll down to the part of ‘Free Python Programming Books’ and from then onwards but I suggest you read the whole information page). One more link to help you get started. But the real task lies with you: You have to find out which one suits you best. :wink:

1 Like