Converting strings into sets of words than intersecting sets. solution in Clear category for Common Words by 2010min0ru
def checkio(line1: str, line2: str) -> str:
"""List common words that could be found in both strings."""
return ','.join(sorted(set(line1.split(',')) & set(line2.split(','))))
if __name__ == '__main__':
# These "asserts" are used for self-checking and not for an auto-testing
assert checkio('hello,world', 'hello,earth') == 'hello'
assert checkio('one,two,three', 'four,five,six') == ''
'four,five,one,two,six,three') == 'one,three,two'
print("Coding complete? Click 'Check' to earn cool rewards!")
Oct. 30, 2020