When solving the following problem: "Assuming you have a random list of strings (for example: a, b, c, d, e, f, g), write a program that will sort the strings in alphabetical order. You may not use the sort command."
I run into the problem of running strings through the following code, which sometimes gets me duplicated strings in final list
I am fairly new to python and our class just started to look at numpy, and functions in that module, and im not sure of any being used in the code (except any sort function).
import numpy as np
list=[]
list=str(input("Enter list of string(s): "))
list=list.split()
print() # for format space purposes
listPop=list
min=listPop[0]
newFinalList=[]
if(len(list2)!=1):
while(len(listPop)>=1):
for i in range(len(listPop)):
#setting min=first element of list
min=listPop[0]
if(listPop[i]<=min):
min=listPop[i]
print(min)
listPop.pop(i)
newFinalList.append(min)
print(newFinalList)
else:
print("Only one string inputted, so already alphabatized:",list2)
Expected result of ["a","y","z"]
["a","y","z"]
Actual result...
Enter list of string(s): a y z
a a a ['a', 'a', 'a']
Enter list of string(s): d e c
d c d d ['c', 'd', 'd']
letters = ['a', 'b', 'c'...]. Then, when you get a string, usenp.where()ornp.argwhere()to get the index of the letter ('a' will be 0, 'z' will be 25). Then, after getting the indices of two letters, you can determine which is smaller. If you don't need to use Numpy, you can use a string instead:letters = 'abcdef...'. Then, useletters.find('a')to get the index of the letter ('b' would be the second position). Once again, compare the indices.numpyin this sorting? or is this sorting task left over from some unit that you studied before?