0
Which code turns user's input into alphabetical order?
2 ответов
0
Help on 'sorted' function
sorted(list) -> returns the list with alphabetic order
So, you can convert the user's input (string) to list then sort it in alpha. order, then convert it back to string.
def alpha(text):
_list = [] #the list of character of text
for c in text:
_list.append(c) #add each character to the list
_list = sorted(_list) #make it sorted by alpha order
final_text = "".join(_list) #str.join is a function that inserts that str in the list per index (in this case it will convert the _list to a string
return final_text