I had the same error coming, it ended up being because of Erroneous Indentation.
I was converting the list to an array and then trying to append to the array, thus it showed the error.
I had to just remove those two statements from an outer 'for' loop, and indent them properly outside the loop.