Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find if a string has a character which isn't in another string

For example I can have the string 'acagtcas' and I want to find if the string has any characters that aren't a, c, g or t. I've tried using not but I haven't been able to make it work. How can I implement this?

like image 857
Miguens Avatar asked Oct 19 '25 01:10

Miguens


1 Answers

You can use set.difference:

s = "acagtcas"

x = set(s).difference("acgt")
print(x)

Prints:

{'s'}
like image 54
Andrej Kesely Avatar answered Oct 21 '25 15:10

Andrej Kesely