0

I have a list containing lists in two dimensions, so for example records[a][b] would be one value in it. There are some criteria that should filter it. I used a combination of "for" and "if" to do so and it worked. Then some additional criteria had to be added that filter out points that have coordinate value, which are in a range of 10*10 units around the currently iterated-over point. However my code compiles but does not do anything and I can't figure out why (as I am still new to Python).

for rec in range(1,len(records)-1):
    for koor in range(1,len(records)-1):
        if records[rec][4]+10 >= records[koor][4] >= records[rec][4]-10 and\
           records[rec][5]+10 >= records[koor][5] >= records[rec][5]-10 and\
           -1.00036 <= records[rec][8] / records[koor][8] <= 1.00036:

What I thought it would do is look for points in the defined area (line 3 & 4) and only let them pass under the condition of line 5. But it lets everything pass. Why is that not working?

Edit: One entry in the form of records[a] looks like this: ['30.12.1899 08:47:00', '7.2.2003 00:00:00', 48.82, 11.2, 4441489.89, 5410519.48, 4, 1.2, 508.55, 0.0, 0.0, 2].

Homerun_
  • 13
  • 5

1 Answers1

0

Try this:

for rec in records[1:-1]:
    for koor in records[1:-1]:
        if rec == koor:
            # handle this some other way
        elif all(20 >= koor[x] - rec[x] + 10 >= 0 for x in [4, 5]) and abs(rec[8] / koor[8]) <= 1.00036:
Ma0
  • 15,057
  • 4
  • 35
  • 65
  • I just saw the `python 2.4` tag. not sure whether `all` existed back then. – Ma0 Mar 16 '17 at 10:52
  • Sorry, I should have mentioned that more clearly. I have to use Python-2.4.3 in order to use a certain library. Right now the elif line gives me the error: "TypeError: 'int' object has no attribute '__getitem__' " – Homerun_ Mar 16 '17 at 10:55