I am looking for some code in Python which could return k
largest numbers from an unsorted list of n
numbers. First I thought to do this by sorting the list first, but this might turn out to be very bulky.
For example the list from which I want to find k
largest number be list1
> list1 = [0.5, 0.7, 0.3, 0.3, 0.3, 0.4, 0.5]
Here n = 7
and if k = 3
, that is if I want to find 3 largest numbers from a list of 7 numbers then output should be 0.5, 0.7, 0.5
How can this be done?