Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Common Words by Michal_Cichy
def checkio(first, second):
first+=","
second+=","
common=[]
slowa1=[]
slowa2=[]
a=0
b=0
for i in range(len(first)):
if first[i]==",":
b=i
slowa1.append(first[a:b])
a=i+1
a=0
b=0
for i in range(len(second)):
if second[i]==",":
b=i
slowa2.append(second[a:b])
a=i+1
for i in slowa1:
if i in slowa2:
common.append(i)
if len(common)==0:
return ""
else:
common.sort()
wynik=common[0]
for i in range(1,len(common)):
wynik+=","+common[i]
return wynik
#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"
Dec. 11, 2016