I need to check if a string exists or not within a larger set of strings and if it does exist to add the string which contains it to another list. I have code that checks the presence ok and it works but it cannot add the string because of my implementation.
Code
test_list = ['temp', 'temperature']
b = ['sunny', 'cloudy', 'stempy', 'temp','newtemperature']
hits = []
hit_name = []
for test_string in b:
res = any(item in test_string for item in test_list)
if res == True:
hit_name.append(item)
hits.append(res)
# print result
print('\n'*2, hits)
Desired output
hit_name = ['stempy', 'temp','newtemperature']
