Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Common Words by tomasz.pucka
def checkio(first, second):
second+=','
first+=','
common_words=""
letter_counter=0
last_letter_pos=-2
for char in first:
letter_counter+=1
if(char==","):
word=first[last_letter_pos+2:letter_counter]
last_letter_pos=letter_counter-2
if(word in second): common_words+=word+" "
common_words=common_words.replace(",","")
cwl=common_words.split()
cwl=sorted(cwl)
common_words=",".join(cwl)
return common_words
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("hello,world", "hello,earth") == "hello", "Hello"
assert checkio("one,two,three", "four,five,six") == "", "Too different"
assert checkio("one,two,three", "four,five,one,two,six,three") == "one,three,two", "1 2 3"
Oct. 29, 2016