python - how to find letters that don't occur in either string? -
i need write code prints out letters don't appear in either of 2 strings. have opposite. prints out letters occur in both strings. here code. i'm not sure how change it.
s1 = input('enter string:\n') s2 = input('enter second string:\n') s1 = set(s1) s2 = set(s2) def notinother(s1, s2): chars = [] char in (s1,s2): if char not in s2: if char not in s1: chars.append(char) print(chars)
here i'm trying write simple , basic answer.
a string containing ascii letters can found in string
module
from string import ascii_letters letters
but of course can write directly in code
letters = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
you need 2 strings characters excluded
s1, s2 = 'abcdef', 'stuvwxyz'
to solve problem, can build list remaining letters using list comprehension (i think code self explanatory)
rl = [c c in letters if c not in s1+s2]
eventually, if want print result of code can use .join()
method of null string
print(''.join(rl))
that gives you
ghijklmnopqrstuvwxyzabcdefghijklmnopqr
Comments
Post a Comment