Tackling a few puzzle problems on a quiet Saturday night (wooohoo... not) and am struggling with sort(). The results aren\'t quite what I expect. The program iterates throug
The comparator operator is treating your input as strings instead of integers. In string comparsion 2 as the 3rd letter is lexically greater than 1.
reversed = str(mult)[::-1]
No need to convert to int. mult already is an int and as you have checked it is a palindrome it will look the same as reversed, so just:
list.append(mult)
You're sorting strings, not numbers. Strings compare left-to-right.
Your list contains strings so it is sorting them alphabetically - try converting the list to integers and then do the sort.
You are sorting strings, not numbers. '101101' < '10201'
because '1' < '2'
. Change list.append(reversed)
to list.append(int(reversed))
and it will work (or use a different sorting function).
No, it is sorting properly, just that it is sorting lexographically and you want numeric sorting... so remove the "str()"