Python Forum
how to sort a list without .sort() function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to sort a list without .sort() function
#1
Hey there.

I would like to understand how I can sort the strings in a list alphabetically, but without using the sort/sorted function.

For example, I have the following list:

list['d', 'v', 'c', 'a', 'b']

Thanks a lot!
Reply
#2
Implement a sorting algorithm - there are quite a few and differ in performance characteristics amongst other things. Why, though?
Reply
#3
There are lots of sorting algorithms. Insertion sort is probably the easiest to understand. It is much like sorting cards as you pick them up one by one and place them in order in your playing hand. Bubble sort is also pretty easy to understand. These sorts are not very efficient. The more efficient sorts are also a bit abstract and not intuitively obvious at first glance. Well known sorts like Quick Sort and Heap Sort fall in this category.

You can find examples of all these sorts online. Many with fancy graphics to help demonstrate how the sort works.
Reply
#4
To make things more interesting you can try sorting in language which alphabet contains non-ascii letters as well.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How Do I Calculate an Average and Sort File Data in Python? jadongreen 1 289 Jan-21-2026, 12:19 AM
Last Post: Pedroski55
Question Frog codility leap sort variant MoreMoney 5 2,655 Apr-06-2024, 08:47 PM
Last Post: deanhystad
  How to sort a list with duplicates and return their unique indices. Echoroom 3 10,427 Sep-23-2022, 07:53 AM
Last Post: deanhystad
  sorting a list using unicodes acending order, no loops, no sort(), using recursion lrn2codee 14 11,774 Jun-23-2021, 07:33 PM
Last Post: deanhystad
  Sort and merge flintstone 1 2,757 Jun-14-2021, 07:32 PM
Last Post: Larz60+
  How can I sort my column so that NaN is at the bottom? soft 3 4,173 Feb-06-2021, 01:02 PM
Last Post: ibreeden
  Sort on basis of (name,age,score) pyzyx3qwerty 9 13,720 May-14-2020, 08:29 AM
Last Post: pyzyx3qwerty
  Sort last pyzyx3qwerty 7 7,837 May-05-2020, 02:58 PM
Last Post: DeaD_EyE
  insertion sort brobro 3 3,760 Apr-24-2020, 01:29 PM
Last Post: Godserena
  Sort objects by protected properties. Sigriddenfeta 1 3,202 Mar-17-2020, 04:11 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020