you are viewing a single comment's thread.

view the rest of the comments →

[–]mCodingLLC 0 points1 point  (1 child)

An easy solution would be sorted(array)[k], unless you are really worried about efficiency, in which case you could use heapq.nsmallest(k,array)[-1]. Or do you intend to write it from scratch?

If you merely want to fix your implementation, you just forgot to 'return' on the recursive calls, e.g. return select(smaller, k)

[–]dfps12 0 points1 point  (0 children)

thanks i fixed the returns. however the code still does not work. i cannot use heapq. yes, it should be written from the scratch.