I am comparing two arrays in Python.
The 1st array is a list of words from a query string. The second array is the list of words to be excluded from the query.
I have to compare these arrays and exclude words from the first array which are contained in the second array.
I tried to solve this by comparing each word from the first array to the whole of second array and continuing until all the words from the first array are exhausted:
for i in q_str:
if q_str[i] in stop_arr:
continue
else:
sans_arr[j] = q_arr[i]
j = j + 1
Where q_str is the query array, stop_arr contains the words to be excluded, and
sans_arr is a new array with the words excluded.
This code generates an error:
list indices must be integers not str
This code generates new array with all elements of
q_strthat not exists instop_arr:Disclaimer: I don’t know if q_str is an array of string because you talk about a query array.