Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python Sort List – How to Order By Descending or Ascending
- In Python, you can sort data by using the sorted() method or sort() method.
- In this article, I will provide code examples for the sorted() and sort() methods and explain the differences between the two.
- What is the sort() method in Python?
- This method takes a list and sorts it in place. This method does not have a return value.
- In this example, we have a list of numbers and we can use the sort() method to sort the list in ascending order.
- my_list = [67, 2, 999, 1, 15]
- # this prints the unordered list
- print("Unordered list: ", my_list)
- # sorts the list in place
- my_list.sort()
- # this prints the ordered list
- print("Ordered list: ", my_list)
- for more: https://www.clictune.com/eAjS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement