Advertisement
sissou123

Untitled

Mar 27th, 2022
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. Python Sort List – How to Order By Descending or Ascending
  2. In Python, you can sort data by using the sorted() method or sort() method.
  3.  
  4. In this article, I will provide code examples for the sorted() and sort() methods and explain the differences between the two.
  5.  
  6. What is the sort() method in Python?
  7. This method takes a list and sorts it in place. This method does not have a return value.
  8.  
  9. In this example, we have a list of numbers and we can use the sort() method to sort the list in ascending order.
  10.  
  11. my_list = [67, 2, 999, 1, 15]
  12.  
  13. # this prints the unordered list
  14. print("Unordered list: ", my_list)
  15.  
  16. # sorts the list in place
  17. my_list.sort()
  18.  
  19. # this prints the ordered list
  20. print("Ordered list: ", my_list)
  21. for more: https://www.clictune.com/eAjS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement