0
p=('99','655','864','654')
e=sorted(p)

the result is ['654', '655', '864', '99'] why is 99 at last? It should be first.

Kraigolas
  • 5,121
  • 3
  • 12
  • 37
  • 5
    You are sorting strings, not integers. That means the order is lexicographical – shriakhilc Jan 31 '22 at 04:22
  • 3
    Just use the `key` parameter to sort as integers: `sorted(p, key=int)` This will pass each item to `int()` before considering it's sorting order. – Mark Jan 31 '22 at 04:26
  • p=('99','655','864','654') p = [int(x) for x in p] e=sorted(p) print(e) – Quack Jan 31 '22 at 04:39

0 Answers0