Hi, I am solving elementary puzzles with checkio now and one question has arisen.
The task is as follows:
Two lines are given with comma separated words. Try to find what is common between these lines. Words within each line are not repeated.
Your function should find all the words that appear in both lines. The result should be presented as a string with words separated by commas and sorted alphabetically.
I did this:
def checkio(first, second): dbl = "" words = set(first.split(",") + second.split(",")) for word in words: if word in first.split(",") and word in second.split(","): dbl += " ".join(word) return sorted(dbl) checkio("one,two,three", "two,four,five,three") But, the string is supplemented character by character and I do not understand why. That is, instead of
two,three he leads
t,w,ot,h,r,e,e I want to figure out why, tell me where to look?