-2

I want to input 5 names and then sort them manually.

Is there any shorter solution than this??

def swap(x,y):
  L[x],L[y]=L[y],L[x]
  L = input("Enter names separated by space: ")
  L = L.split(" ")
    for x in range(len(L)):
       for y in range(len(L)-1):
          if L[y] > L[y+1]:
            swap(y,y+1)
print(L)
Mikev
  • 2,012
  • 1
  • 15
  • 27

1 Answers1

0

In python you can do :

L =  input("Enter names separated by space: ")
L =   L.split(",")
# sort the list
L.sort()
Mohit Harshan
  • 1,916
  • 1
  • 18
  • 41