There are two lists, string and query, both containing strings. I want to create a function that returns a 2D array showing:
For example, if we have
As:
So the function should return the array [[3, 2], [1, 3], [1, 2]]
I have tried the following:
def countstuff(string, query)
result = []
for i in query:
array = [[sum(i in j for j in string], len(i)]]
result.append(array)
return result
But before I get to try the function, it returns SyntaxError: invalid syntax.
I can't get my head around this, please help, thank you.
Hi after fiddling some more, I found another solution, thanks everyone.
def countstuff(string, query):
result = []
for i in query:
array = [sum(i in j for j in string)]
array.append(len(i))
result.append(array)
return result