"vince spicer" <vinces1...@gmail.com> wrote
def compare(x,y):
try:
return cmp(int(x), int(y))
except:
pass
try:
int(x)
except:
return -1
try:
int(y)
except:
return 1
return 0
Or
def compare(x,y):
if type(x) == str: return -1
if type(y) == str: return 1
return cmp(x,y)
Runs into problems if you have multiple strings and want them
sorted too...
L = [4,3,'word','picture',1,2,3]
sorted(L, cmp=comp)
['picture', 'word', 1, 2, 3, 3, 4]
L = [4,3,'picture','word',1,2,3]
sorted(L, cmp=comp)
['word', 'picture', 1, 2, 3, 3, 4]
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor