Skip to content

learndataa

Imagine data to solve problems

  • Home
  • YouTube Courses
  • Udemy Courses
  • Training
  • About
  • Privacy Policy
  • Facebook
  • Twitter
  • Instagram
  • Pinterest
  • Home
  • YouTube Courses
  • Udemy Courses
  • Training
  • About
  • Privacy Policy
  • Facebook
  • Twitter
  • Instagram
  • Pinterest

Sort a list

20 August 2020

Code

Sort ascending:

# Create a list
x = [3,4,1,5,2]

# Sort
x.sort() # default is (reverse=False)

# Output
print(x)
[1, 2, 3, 4, 5]

.

Sort descending:

# Create a list
x = [3,4,1,5,2]

# Sort
x.sort(reverse = True)

# Output
print(x)
[5, 4, 3, 2, 1]

.






Any errors in code above?
Please send a message.

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
  • Home
  • YouTube Courses
  • Udemy Courses
  • Training
  • About
  • Privacy Policy
  • Facebook
  • Twitter
  • Instagram
  • Pinterest
learndataa, Website Powered by WordPress.com.
  • Subscribe Subscribed
    learndataa

    Have a WordPress.com account? Log in now.

  • learndataa
    Copy shortlinkView post in Reader
    Manage subscriptionsSign upLog in
    Report this content
    Collapse this bar