I have an unsorted list of integers dist
containing positive and negative integers, and I would like to return the index
of the minimum number
that is >0
. Here is my code:
dist = [-4,1,-2,4,5]
curr = dist.index(min(i) for i in dist if i>0)
print(curr)
I run into a "ValueError(): generator is not in list"
, and I do understand the issue, the issue is that the output of the list comprehension is a generator, but how can I wrap it around something to make it valid? Usually I throw a list()
around it, but this clearly will not work in the above case.
P.S. I know there are other ways to do it like using sort(), but in the actual problem I am solving, dist
contains thusands of numbers, and I would like to avoid sorting the list. If there are other easier ways to do it, please do let me know!