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, 2019 in Python by Piyush
92 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, 2019 by Omkar
• 69,000 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 aryya
• 7,350 points
86 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,760 points
149 views
+3 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
1,957 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, 2019 in Python by Junaid
83 views
0 votes
1 answer
+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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 756 views
0 votes
0 answers
+4 votes
6 answers
+2 votes
3 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]

Try using this question by list comprehension: a=[4,7,3,2,5,9] print([x for ...READ MORE

answered Dec 8, 2019 in Python by vinaykumar
• 160 points
2,148 views
0 votes
1 answer