1
n = input('print n:')
k = input('print k')
a = input('print'+str(n)+'numbers:')
s = str(a)
Lst = s.split()
map_object = map(int, Lst)
lst = list(map_object)

I have the rest done, and I don't know how to find and print the k smallest integer.

inputs:

10(n) 3(k)

1 3 3 7 2 5 1 2 4 6(n amount of numbers)

outputs:

3

1 Answers1

2

You can have duplicate numbers, so first we are getting rid of them by using set():

no_duplicates = set(lst)

Then we sort it, which will return us sorted list:

sorted_list = sorted(no_duplicates)

Then we get your desired number (you haven't converted k to int, so we will do it here):

kth_smallest = sorted_list[int(k)-1]
Tugay
  • 2,057
  • 5
  • 17
  • 32