Break down the problem into pieces.
Start off by making a function that checks if one string is in a sequence of strings:
def check_one(string, seqs):
for seq in seqs:
if string not in seq:
return False
return True
Then make a function that checks all strings by using this function:
def check_all(strings, seq):
result = []
for string in strings:
if check_one(string, seq):
result.append(string)
return result
Then simply call check_all()
:
short_str_list = ["aga", "ttt", "aca"]
seq_list = ["atcgcgtacat", "acatcgggattt", "tttacagtgtgtggg"]
print(check_all(short_str_list, seq_list))
# ['aca']
You can also use all()
, filter()
and list comprehensions to to do this in one line:
print([x for x in short_str_list if all(x in y for y in seq_list)])
# ['aca']
print(list(filter(lambda x: all(x in y for y in seq_list), short_str_list)))
# ['aca']