Skip to content

Instantly share code, notes, and snippets.

@Robofied
Last active February 5, 2019 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/876263b5bb2097134b65419e3bad5498 to your computer and use it in GitHub Desktop.
Save Robofied/876263b5bb2097134b65419e3bad5498 to your computer and use it in GitHub Desktop.
## sort() method
l5 = [4,5,1,2,8,9,1]
## It will sort the list in ascending order.
l5.sort()
print(l5)
#[Output]:
#[1, 1, 2, 4, 5, 8, 9]
l5 = [4,5,1,2,8,9,1]
## It will sort in reverse order i.e, descending
l5.sort(reverse= True) print(l5)
#[Output]:
#[9, 8, 5, 4, 2, 1, 1]
## sorted() method
l6 = [4,5,1,2,8,9,1]
## using sorted it will sort for that time only.
sorted(l6)
#[Output]:
#[1, 1, 2, 4, 5, 8, 9]
## If we will print the list it will same only
print(l6)
#[Output]:
#[4, 5, 1, 2, 8, 9, 1]
## reverse() method
## Reversing the list
l6.reverse()
print(l6)
#[Output]:
#[1, 9, 8, 2, 1, 5, 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment