I am struggling with Python's sort().
My program iterates through every integer combination from 100 to 999 and checks if their products are palindromic. If they are, my program appends the product to a list. I need the list sorted.
Here's my program:
list = [] # list of numbers
for x in xrange(100,1000): # loops for first value of combination
for y in xrange(x,1000): # and 2nd value
mult = x*y
reversed = str(mult)[::-1] # reverses the number
if (reversed == str(mult)):
list.append(reversed)
list.sort()
print list[:10]
Which nets:
['101101', '10201', '102201', '102201', '105501', '105501', '106601', '108801',
'108801', '110011']
Clearly, index 0 is larger then 1. Any idea what's going on? I have a feeling it's got something to do with trailing/leading zeroes, but I had a quick look and I can't see the problem.