0

This was working a few minutes ago but now I can't get it to work at all.

for i in range(0, len(find)):
    for j in range(0, len(X)):
        print(find[i], X[j])
        if find[i] == X[j]:
            longitude.append(float(lon[j]));
            latitude.append(float(lat[j]));

print(len(longitude))

LS5  LS6
LS5  LS7
LS5  LS6
LS5  LS7
LS6  LS6
...
0

for some reason its clearly equal but doesn't go through the if statement. any idea why this is happening?

  • did you check white space? – galaxyan May 01 '18 at 19:01
  • most probably you have extra whitespaces, try `print('"{}"'.format(find[i]), '"{}"'.format(X[j]))`. – hoefling May 01 '18 at 19:01
  • Two objects can have the same *apparent* string representation without being equal. What's the output of `print(repr(find[i]), repr(X[j]))`? – chepner May 01 '18 at 19:02
  • Can you fill this in a bit so that others can reproduce the problem? (What are `find`, `X`, `lon`, and `lat`?) – glibdud May 01 '18 at 19:02
  • I did the print and it returns: "LS8 " "LS7" it seems that find file has a tab after, any idea how i can remove this whitespace? –  May 01 '18 at 19:05
  • Use `str.strip` to remove whitespaces. – MegaIng May 01 '18 at 19:06
  • 1
    Possible duplicate of [Remove all whitespace in a string in Python](https://stackoverflow.com/questions/8270092/remove-all-whitespace-in-a-string-in-python) – hoefling May 01 '18 at 19:06
  • adding .rstrip() has removed the whitespace on the right and is now working. thank you guys –  May 01 '18 at 19:08

0 Answers0