I want to sort the numbers in a list based on the last digit.
Here is my code:
import sys
list1 = sys.argv[1]
list1_split = list1.split(",")
sorted_numbers = sorted(list1_split, key=lambda x: x%10)
print("Sorted numbers are: ", sorted_numbers)
This is what I get on the command prompt:
C:\Users\john\pythonprojects\test1> testing.py 45,60,51,24,62,49
Traceback (most recent call last):
File "C:\Users\john\pythonprojects\test1\testing.py", line 6, in <module>
sorted_numbers = sorted(list1_split, key=lambda x: x % 10)
File "C:\Users\john\pythonprojects\test1\testing.py", line 6, in <lambda>
sorted_numbers = sorted(list1_split, key=lambda x: x % 10)
TypeError: not all arguments converted during string formatting
The expected output should be: [60, 51, 62, 24, 45, 49]
I can't figure out how to solve this error