Reputation: 2214
How can I check if a string (string1
) contains characters except the ones in the following string (seq_letters
):
string1 = 'SEQ'
seq_letters = 'ATCGRYMKSWHBVDN'
E
and Q
are not in seq_letters.
Upvotes: 3
Views: 976
Reputation: 513
string1 = 'SEQ'
seq_letters = 'ATCGRYMKSWHBVDN'
result = []
for i in string1:
if i not in seq_letters:
result.append(i)
print(result)
Upvotes: 1
Reputation: 82765
Using set.difference
string1 = 'SEQ'
seq_letters = 'ATCGRYMKSWHBVDN'
print(set(string1).difference(seq_letters))
Output:
{'E', 'Q'}
Upvotes: 6