Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Common Words by PythOff
def checkio(first, second):
first += ','
second += ','
first_list = []
second_list = []
res_list = []
j = 0
for i in range(0,len(first)):
if first[i] == ',':
first_list.append(first[j:i])
j = i + 1
k = 0
for l in range(0, len(second)):
if second[l] == ',':
second_list.append(second[k:l])
k = l + 1
for m in first_list:
try:
second_list.index(m)
except ValueError:
pass
else:
res_list.append(m)
res_list = sorted(res_list)
res = ""
for n in res_list:
res += n + ','
res = res[:-1]
return res
#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. 31, 2016