Skip to content
  • YouTube
  • FaceBook
  • Twitter
  • Instagram

Data Analytics Ireland

Data Analytics and Video Tutorials

  • Home
  • Contact
  • About Us
    • Latest
    • Write for us
    • Learn more information about our website
  • Useful Links
  • Glossary
  • All Categories
  • Faq
  • Livestream
  • Toggle search form
  • ValueError: invalid literal for int() with base 10 Value Error
  • YouTube channel lists – Python Lists Python Lists
  • TypeError: Array() Argument 1 Must Be A Unicode Character, Not List array
  • Tkinter python tutorial Python
  • How to Pass a Javascript Variable to Python using JSON Flask
  • how to copy/paste special a range of cells with xlwings Python
  • How To Run Python Validation From Javascript Javascript
  • How To Create An Empty Dictionary In Python python dictionaries

python sort method

Posted on January 12, 2021January 20, 2021 By admin No Comments on python sort method

Estimated reading time: 2 minutes

Why would you sort a list?

It allows efficiency in other algorithms to quickly find data in the list that is used as an input to their code, examples include searching and merging data.

Also, can be used to standardize the data set so that it can have a meaningful representation.

For data visualization purposes having it in order can allow the viewer quickly to attach meaning to what they see in front of them.

There are different sorting techniques as follows:

  • Bubble Sort Algorithm is used to arrange N elements in ascending order.
  • Selection sort is a straightforward process of sorting values. In this method, you sort the data in ascending order.
  • Merge sort splits two lists into a comparable size, sorts them, and then merges them back together.

According to the  Python Organisation website, Python lists have a built-in list.sort() the method that modifies the list in-place.

mylist = [5, 2, 3, 1, 4]
mylist.sort()
print(mylist)
[1, 2, 3, 4, 5]

This method only works for lists.

It also has a very similar method sorted() , which, unlike list.sort, can work on any iterable.

a= {'c':'1','b':'2','a':'3'}

print(sorted(a))
['a', 'b', 'c']

Note that the sorted method only sorts the key value in the dictionary above.

Per programiz.com parameters for the sorted() function are as follows:

sorted() can take a maximum of three parameters:

  • iterable – A sequence (string, tuple, list) or collection (set, dictionary, frozen set) or any other iterator.
  • reverse (Optional) – If, the sorted list is reversed (or sorted in descending order). Defaults to if not provided.
  • key (Optional) – A function that serves as a key for the sort comparison. Defaults to None.

Click how to sort lists in python to get a video tutorial on the above, which may help to explain the concepts further.

python method Tags:iterable, list.sort, paramaters, Python, sorted

Post navigation

Previous Post: Tkinter GUI tutorial python – how to clean excel data
Next Post: python classes

Related Posts

  • String Manipulation in Python python method
  • TypeError: ‘list’ object is not an iterator Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Select your language!

  • हिंदी
  • Español
  • Português
  • Français
  • Italiano
  • What does a data analyst do? Livestream
  • R Tutorial: How to pass data between functions R Programming
  • Python Dictionary Interview Questions Python
  • How do I fix TypeError: unhashable type: ‘list’ Error? Articles
  • How to Generate Random Integers Between 0 and 9 Python
  • how to write subqueries in SQL SQL
  • supervised machine learning vs unsupervised machine learning? machine learning
  • YouTube channel lists – Python working with files Python working with files

Copyright © 2023 Data Analytics Ireland.

Powered by PressBook Premium theme

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT