0

I have a list of floats taken from an sqlite3 db. From it I want to find the first two numbers greater than a number, say 18 in this case, and enumerate their position in the db.

The db list:

pr = [(20.49999999999983,), (16.29999999999967,), (13.799999999999102,), (18.600000000000705,), (9.600000000000364,), (11.599999999999966,), (25.30000000000001,)...]

Hence I try the following:

fnd =([i[0] for i in pr if i[0] > 18])
>>> [20.49999999999983, 18.600000000000705, 25.30000000000001]

for j in fnd:
    print ([i for i,k in enumerate(pr) if k == j])

For which I get 3 empty lists. I am assuming my problem comes from the fact that the float is being rounded when I use the for loop.

for j in fnd:
    print j

>>>20.5, 18.6, 25.3

Can anyone offer a workaround?

ajsp
  • 2,512
  • 22
  • 34

1 Answers1

0

k takes the values of the elements of pr, which are 1-tuples containing numbers.

j takes the values of the elements of fnd, which you constructed as the list of numbers greater than 18.

When you compare k to j, you compare a tuple with a number. They are never equal.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65