Bit stuck on a coding challenge here! I'm writing a function that takes two arguments (strings, queries) and prints the number of times each query string occurs in the input string. I think I'm quite close to figuring this out but my function is currently insensitive to query strings with spaces before/after a query string.
Version 1 (insensitive to query strings containing spaces):
strings = ['ab', ' ab', 'abc']
queries = ['ab', ' abc', ' bc']
def matchingStrings(strings, queries):
for i in range(len(queries)):]
n_matches = strings.count(queries[i])
print(n_matches)
matchingStrings(strings,queries)
Current Output:
1
0
0
Version 2 (attempt to retain quotation marks):
def matchingStrings(strings, queries):
for i in range(len(queries)):
query_to_match = '\'%s\'' % queries[i]
n_matches = strings.count(query_to_match)
print(n_matches)
matchingStrings(strings,queries)
Current Output:
0
0
0
Expected Output:
2
1
0