Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
my solution solution in Clear category for Common Words by defensor
def checkio(line1: str, line2: str) -> str:
# how I solved
# 1. merge line1 and line2 into a list separeted by commas
# 2. from the list pick words which only appears more than once, eliminate duplicated words by using set()
# 3. sort all the picked up word in alphabetical order and join them all into one word
word_list = str(line1 + "," + line2).split(",") #1
common_words = set(word for word in word_list if word_list.count(word) > 1) #2
return ",".join(sorted(common_words)) #3
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!")
July 22, 2021