Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Common words sorted solution in Clear category for Common Words by golosinas
def checkio(line1: str, line2: str) -> str:
""" Input: Two arguments as strings.
Output: The common words as a string.
Precondition:
Each string contains no more than 10 words.
All words separated by commas."""
set_1 = set(line1.split(","))
set_2 = set(line2.split(","))
return ",".join(sorted(list(set_1 & set_2)))
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!")
Sept. 20, 2020
Comments: