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 to sort a list with duplicates and return their unique indices. Echoroom 3 3,354 Sep-23-2022, 07:53 AM
Last Post: deanhystad
  sorting a list using unicodes acending order, no loops, no sort(), using recursion lrn2codee 14 6,246 Jun-23-2021, 07:33 PM
Last Post: deanhystad
  Sort and merge flintstone 1 1,870 Jun-14-2021, 07:32 PM
Last Post: Larz60+
  How can I sort my column so that NaN is at the bottom? soft 3 2,355 Feb-06-2021, 01:02 PM
Last Post: ibreeden
  Sort on basis of (name,age,score) pyzyx3qwerty 9 9,406 May-14-2020, 08:29 AM
Last Post: pyzyx3qwerty
  Sort last pyzyx3qwerty 7 4,666 May-05-2020, 02:58 PM
Last Post: DeaD_EyE
  insertion sort brobro 3 2,156 Apr-24-2020, 01:29 PM
Last Post: Godserena
  Sort objects by protected properties. Sigriddenfeta 1 1,856 Mar-17-2020, 04:11 AM
Last Post: Larz60+
  list and sort query arian29 2 2,165 Sep-18-2019, 06:19 PM
Last Post: ndc85430
  Help with syntax to sort dictionary by value Mark17 2 2,101 Sep-17-2019, 02:19 PM
Last Post: Mark17

Forum Jump:

User Panel Messages

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