+ 6
How to implement selection sort in list where list elements are strings?
a=['ram','ham','sal','david'] x=len(a) for i in range(0,x): small=i for j in range(i+1,x): if a[small]>a[j]: small=a[j] a[small],a[i]=a[i],a[small] print(a) This is my code but it doesn't work
4 Respuestas
+ 6
You almost got it! Try changing lines 6-7 for this:
if a[small]>a[j]:
small = j
+ 5
You’re welcome.
Happy coding!
+ 4
Diego Acero thanks for your suggestions .it worked!
0
I havent tried strings yet, though I understand why how they are ordered, spoilers