I have a list of integer imported via a file
xy = [50, 2, 34, 6, 4, 3, 1, 5, 2]
I am aware of Python: finding lowest integer
However, I wonder how can I print the position of it instead of just finding the smallest number?
Just use the list.index
method:
print xy.index(min(xy))
# 6
If the minimum is repeated, you'll only get the index of the first occurrence, though.
indices = [i for i, x in enumerate(xy) if x == min(xy)] # Indices of all min occurrences
Just in case someone wishes to use for loop:
xy = [50, 2, 34, 6, 4, 3, 1, 5, 2]
t=0
for i in range(len(xy)):
if xy[i]<xy[t]:
t=i
print t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With