I am trying to write a function which takes as argument a list of integers from the user input and sorts them.
I am getting some issues, because if I convert the integers to strings (I thought it could be the best way, because of the commas in the input) and append them in an empty list, I get an error.
Here the function:
def sort_integers(x):
lst = []
for i in x:
lst.append(i)
sorted_list = sorted(lst)
print(sorted_list)
sort_integers(str(input("Enter some numbers: ")))
But if I enter 10, 9, 8 as integers, this is what I get as output:
[',', ',', '0', '1', '8', '9']
Expected output would be: 8,9,10
. I have tried to use sort_integers(int(input("Enter some numbers: ")))
but I get this error:
ValueError: invalid literal for int() with base 10: '10,9,8'
What am I doing wrong?