First solution in Clear category for Common Words by hbczmxy
def checkio(line1: str, line2: str) -> str:
# Get the word list in line1 and line2 respectively
words1 = line1.split(",")
words2 = line2.split(",")
# Find all of the words that appear in both strings
common_words = [word for word in words1 if word in words2]
# Sort the words in common_words in alphabetical order, and then concatenate them into a string
result = ",".join( sorted(common_words) )
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!")
Dec. 10, 2021