-1

I am trying to sort a concatenated list of arrays

k1 = 15 19 3
k2 = 12 13

my code is :

k1 = input().split()
k2 = input().split()
l = k1 + k2
x = l . sort()
print(x)

the output is ['12', '13', '15', '19', '3'] I do not know why the number 3 ends last after doing ascending order. i want the number 3 placed first in ascending order kindly give the correct code

1 Answers1

1

You have a list of strings, which get sorted alphabetically. If you want a list of ints, which get sorted numerically, do:

x = sorted(int(n) for _ in range(2) for n in input().split())
print(x)

which gives you:

15 19 3
12 13
[3, 12, 13, 15, 19]
Samwise
  • 68,105
  • 3
  • 30
  • 44