Im trying to sort a list in Python 3 using Visual Studio Code: I take my list from the arguments in the commandline. The first argument is ignored that's my needle variable. After adding all variables in the lost I want to sort the list. The problem is that it gets sorted in a rather strange way
after 2 comes 21 and then 3 after 5 comes 55 and than 6
This is my commandline:
C:\Users\Gebruikertje\Desktop\Python>python find.py 21 2 3 4 5 6 21 55 3
this is the output:
['2', '21', '3', '3', '4', '5', '55', '6']
This is the part of the code im referring to
import sys
finish = len(sys.argv)
needle = sys.argv[1]
haystack = []
for i in range (2,finish ):
haystack.append(sys.argv[i])
haystack.sort()
print(haystack)
haystack.sort(key = lambda x: int(x))or just make your list integers to begin withkey=int...