python - Order a list of numbers without built-in sort, min, max function - Stack Overflow
Sort a list without using sort() in python with explanation.
sorting a list in python without the sorted function - Stack Overflow
sort function without .sort or sorted()
Is there a particular reason why you can't use those, or do you simply have the impression that you cannot use them for 2D lists? Because you totally can.
EDIT: Your explanation sounds a bit confusing, but if what you're really asking about is sorting a list of strings, that should already be as simple as
strings = [...] sorted_strings = sorted(strings)
By default they'd be in lexicographical order, but if you want to sort by a different criteria, simply supply a boolean filter function to sorted via the key parameter.
Q2. Can we sort a list without sort()?
Q1. Why is sorting important in Python?
Q5. When should I sort manually?
t = a[j]
followed by
a[j] = t
doesn’t seem right. If you meant to swap them, the second one should be:
a[j + 1] = t
But in Python, that’s better written as:
a[j], a[j + 1] = a[j + 1], a[j]
(Of course, in Python, it’s much better written as quicksort.)
Try This -:
for i in range(len(a)):
for j in range(len(a) - 1):
if a[j] > a[j+1]:
a[j+1], a[j] = a[j], a[j+1]
print a
:)
how do I sort a list of lists (2d) which are strings without using .sort or sorted()
I’ve tried making a list of the ACSII elements, and then I realised this requires using .split() to split the string into individual characters, and iterating through each letter/number to check? I’m confused as how to compare the the letters in two different strings, especially the indexing and how to use the nested loops.