my_array.sort sorts the list "in place":

Instead of returning a sorted list, as you seem to expect, my_array.sort() sorts my_array "in place" and doesn't return anything. Try this

my_array = [5, 2, 8, 1, 9]
my_array.sort()
print(my_array)  # [1, 2, 5, 8, 9]

If you want it sorted in descending order use this:

my_array = [5, 2, 8, 1, 9]
my_array.sort()
my_array.reverse()
print(my_array)  # [9, 8, 5, 2, 1]
Answer from TheTridentGuy supports Ukraine on Stack Overflow
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ howto โ€บ sorting.html
Sorting Techniques โ€” Python 3.14.7 documentation
>>> s = sorted(student_objects, key=attrgetter('age')) # sort on secondary key >>> sorted(s, key=attrgetter('grade'), reverse=True) # now sort on primary key, descending [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-list-sort-method
Python List sort() Method - GeeksforGeeks
December 20, 2025 - False (default) sorts in ascending order, True sorts in descending order. By default, sort() arranges elements in ascending order. To sort values from highest to lowest, we use the reverse=True parameter.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ sort-in-python
sort() in Python - GeeksforGeeks
Python ยท a = [5, 3, 8, 1, 2] a.sort() ... Parameters: key: A function that decides how elements are compared ยท reverse: If True, sorts the list in descending order ยท...
Published: January 13, 2026
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python: How to Sort Arrays In Ascending and Descending Order (String and Int Arrays) - YouTube
How to Sort Arrays In Ascending and Descending Order In Python (String and Int Arrays)Greetings, today we are here with a video on how to sort the data in yo...
Published: November 10, 2022
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ problem with sorting in descending order
r/learnpython on Reddit: Problem with sorting in descending order
October 6, 2023 -

Hi, I am trying to sort in descending order in jupyter notebook

I tried from:StackExchange

import numpy as np #import numpy
games = np.array(['FIFA 2020','Red Dead Redemption','Fallout','GTA','NBA 2018','Need For Speed'])
print(games)
print("1",np.sort(games))
games = np.sort(games)
np.sort(games, order='descending')

But I am getting the error

ValueError: Cannot specify order when the array has no fields. 

Somebody, please guide me.

Zulfi.

Top answer
1 of 2
3
I think you are misunderstanding the order parameter. It doesn't do what you seem to think it does: >>> import numpy as np >>> help(np.sort) Help on _ArrayFunctionDispatcher in module numpy: sort(a, axis=-1, kind=None, order=None) Return a sorted copy of an array. Parameters ---------- ... order : str or list of str, optional When `a` is an array with fields defined, this argument specifies which fields to compare first, second, etc. A single field can be specified as a string, and not all fields need be specified, but unspecified fields will still be used, in the order in which they come up in the dtype, to break ties. So order requires your array to have pre-defined "fields", whose members you pass in as order in the order you'd like them sorted according to. "descending" is obviously not a "field" of your array, hence it's not working. Note that despite ascending-order sorting seeming to work in your sample code, if you specify the order as such, you get the same error: >>> import numpy as np >>> games = np.array(['FIFA 2020','Red Dead Redemption','Fallout','GTA','NBA 2018','Need For Speed']) >>> np.sort(games, order='ascending') Traceback (most recent call last): ... ValueError: Cannot specify order when the array has no fields. Looking into this, it seems numpy.sort actually doesn't support descending order. So to achieve the same, just sort in ascending order, then slice in reverse: >>> np.sort(games)[::-1] array(['Red Dead Redemption', 'Need For Speed', 'NBA 2018', 'GTA', 'Fallout', 'FIFA 2020'], dtype='
2 of 2
3
Do you need numpy here? Seems overkill. games = ['FIFA 2020','Red Dead Redemption','Fallout','GTA','NBA 2018','Need For Speed'] sorted(games, reverse=True)
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 4183506 โ€บ python-list-sort-in-descending-order
Python list sort in descending order - Stack Overflow
How can I sort this list in descending order? timestamps = [ "2010-04-20 10:07:30", "2010-04-20 10:07:38", "2010-04-20 10:07:52", "2010-04-20 10:0...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ numpy โ€บ how-to-use-numpy-argsort-in-descending-order-in-python
How to use numpy.argsort in Descending order in Python - GeeksforGeeks
July 23, 2025 - Now, to obtain the indices that sort the array in descending order, we first negate the array using -arr and then use argsort() on the negated array to get the indices in descending order.
๐ŸŒ
PREP INSTA
prepinsta.com โ€บ home โ€บ python program โ€บ python program to sort an array in ascending and descending order
Sorting of array in ascending and descending order in Python | PrepInsta
July 26, 2021 - Use arr.sort(reverse=False) or arr.sort() for ascending order of array. Use arr.sort(reverse=True) for descending order of array
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ sort array in python
Effortless Array Sorting in Python: A Step-by-Step Guide
November 13, 2024 - Let's explore the foundational methods Python offers for this purpose. ... reverse (optional): A boolean value. If True, the list is sorted in descending order; if False (default), it's sorted in ascending order.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ list โ€บ sort
Python List sort() (with Code Visualization)
numbers = [11, 3, 7, 5, 2] # Sort in ascending order numbers.sort() print(f'Ascending order: {numbers}') # Sort in descending order numbers.sort(reverse=True) print(f'Descending order: {numbers}')
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_sorted.asp
Python sorted() Function
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The sorted() function returns a sorted list of the specified iterable object. You can specify ascending or descending order.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.sort.html
numpy.sort โ€” NumPy v2.5 Manual
Sort order. If True, the returned array will be sorted in descending order. If False or None, the returned array will be sorted in ascending order. Values that are NaN are sorted to the end for both orders.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ list-sort()
Python List sort(): Master Data Sorting | Learn Now
You can sort the list in descending order by passing reverse=True as an argument: ... This method sorts the list based on the specified sorting criteria, making it one of Python's most commonly used features for data organization.
๐ŸŒ
Real Python
realpython.com โ€บ python-sort
How to Use sorted() and .sort() in Python โ€“ Real Python
October 22, 2025 - The reverse flag can be set to sort in descending order.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_sort.asp
NumPy Sorting Arrays
Ordered sequence is any sequence that has an order corresponding to elements, like numeric or alphabetical, ascending or descending. The NumPy ndarray object has a function called sort(), that will sort a specified array.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_sort_arrays.htm
Python - Sort Arrays
... The function returns a new list containing all items from the iterable in ascending order. Set reverse parameter to True to get a descending order of items. The sorted() function can be used along with any iterable.