Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Common Words by _ukasz_Mas_owski
def checkio(first, second):
strFirst = first.split(",")
strSecond = second.split(",")
finalString = []
#finalString = ""
mainString = ""
if len(strFirst) > len(strSecond):
iLength = len(strFirst)
mainString = strFirst
otherString = strSecond
else:
iLength = len(strSecond)
mainString = strSecond
otherString = strFirst
for word in mainString:
if word in otherString:
finalString.append(word)
result = sorted(finalString)
end = ""
i = 0
if len(result) > 1:
while i < len(result):
if i == 0:
end = end + result[i]
else:
end = end + "," + result[i]
i = i + 1
elif len(result) == 1:
end = end + str(result[0])
else:
end = ""
print(len(finalString))
print(end)
print(finalString)
print(result)
return end
#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"
Jan. 23, 2017