This is not based on efficiency, and has to be done with only a very very basic knowledge of python (Strings, Tuples, Lists basics) so no importing functions or using sort/sorted. (This is using Python 2.7.3).
For example I have a list:
unsort_list = ["B", "D", "A", "E", "C"]
sort_list = []
sort_list needs to be able to print out:
"A, B, C, D, E"
I can do it with numbers/integers, is there a similar method for alphabetical order strings? if not what would you recommend (even if it isn't efficient.) without importing or sort functions.
Here's a very short implementation of the Quicksort algorithm in Python:
It's a toy implementation, easy to understand but too inefficient to be useful in practice. It's intended more as an academic exercise to show how a solution to the problem of sorting can be written concisely in a functional programming style. It will work for lists of comparable objects, in particular for the example in the question:
just for fun:
the average complexity should be factorial and the worst case infinite
Python already know which string is first and which is next depending on their ASCII values
for example:
so we can write a simple bubble sort algorithm to sort the list of strings
Result:
There are many standard libraries available by which can be done using single line of code.
even simpler:
This uses only the
min()
built-in andlist
object methods:It destroys the unsorted list, so you might want to make a copy of it and use that.