I am wondering why the following situation may occur:
I have a list:
all_hits = list1 + list2
length_hits = len(all_hits)
i = 0
while i < int(length_hits) - 1:
if len((all_hits[i])[1]) >=3:
Do x
else:
Do y
This gives me an error:
File "file.py", line z, in Function:
if len((all_hits[i])[1]) >= 3:
IndexError: list index out of range
So far:
- If I write each
all_hits[i][1]
which is >=3 characters long to a file I reach about 18,000 entries but if I printlen(all_hits)
the answer is 39,000 elements. - I can print the
all_hits[-1]
entry and it does not correspond with the final entry in the written list.
As far as I can see I am not altering the original list.
Why?! I have been 2 days on this problem and it is driving me crazy.
Edit: 3. I have printed the final entry and a few after/before it to ensure they have the correct number of elements and everything looks ok there.
Edit and Thank you:
Thanks everyone. You were, of course, correct. One of my entries had, out of nowhere, only one list object. I don't know how or why but that's a different kettle of fish altogether!
Thank you for your help!