Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
three lines better than one solution in Clear category for Common Words by lucas.stonedrake
#decent solution
def checkio(line1: str, line2: str) -> str:
line1 = set(line1.split(',')) #split by ',' and make a set
line2 = set(line2.split(',')) #split by ',' and make a set
return ','.join(sorted(list(line1 & line2)))
# one line but not very readable
def checkio(line1: str, line2: str) -> str:
return ','.join(sorted(list(set(line1.split(',')) & set(line2.split(',')))))
if __name__ == '__main__':
print("Example:")
print(checkio('hello,world', 'hello,earth'))
# 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') == ''
assert checkio('one,two,three',
'four,five,one,two,six,three') == 'one,three,two'
print("Coding complete? Click 'Check' to earn cool rewards!")
Oct. 29, 2020