Print a list in both ascending and descending order

0 votes

I use sort() in Python but it sorts the list in ascending, how to sort it in descending order?

Feb 6 in Python by Piyush
22 views

1 answer to this question.

0 votes

You can use listName.sort(reverse=True). This will sort the list in descending order. 

>>> numbers = [3,5,6,2]
>>> numbers.sort(reverse=True)
>>> print(numbers)
>>> 6 5 3 2
answered Feb 6 by Omkar
• 67,290 points

Related Questions In Python

0 votes
0 answers

Storing a list of arrays into a CSV file and retrieving it back in a different program

This is the code that I am ...READ MORE

Jun 6, 2018 in Python by ariaholic
• 7,340 points
36 views
0 votes
1 answer

How to Print a List in Python

ou are using Python 2.x syntax with ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
69 views
+2 votes
1 answer

Print the odd and even factors of a number in Python

x = int(input("Enter any number \n")) print("The factors ...READ MORE

answered Nov 19, 2018 in Python by Nabarupa
366 views
0 votes
1 answer

Is there a way to list out in-built variables and functions of Python?

The in-built variables and functions are defined ...READ MORE

answered May 14 in Python by Junaid
30 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 174 views
+4 votes
6 answers
0 votes
2 answers

Write a for loop that prints all elements of a list and their position in the list. a = [4,7,3,2,5,9]

a = [4,7,3,2,5,9] b = enumerate(a) for i in ...READ MORE

answered Jul 15 in Python by Kei Tee

edited Jul 22 by Kalgi 121 views