Shiva
Shiva

Reputation: 73

Retrieving float values from the list in Python

I am trying to fetch the values from an list containing float values which throws the following error,

list = [0.98,0.97,0.95,0.96,0.99,0.99]


for a in list:
    if list[a] >=0.98:
        print("some output")

Error:

TypeError: list indices must be integers, not float 

Upvotes: 0

Views: 287

Answers (1)

U13-Forward
U13-Forward

Reputation: 71570

a is already the value, so you can do:

for a in list:
    if a >=0.98:
        print("some output")

If it was the index, your code will work, but since it isn't, you have to do mine.

Upvotes: 8

Related Questions