Write the function getCommonLetters(word1, word2)
that takes in two words as arguments and returns a new string that contains letters found in both string. Ignore r
you can use set()
and set intersection to find the common elements of two sets -
def getCommonLetters(word1, word2):
return ''.join(sorted(set(word1) & set(word2)))
& is for set intersection
.
Example/Demo -
>>> def getCommonLetters(word1, word2):
... return ''.join(sorted(set(word1) & set(word2)))
...
>>> getCommonLetters('apple','google')
'el'
>>> getCommonLetters('microsoft','apple')
''