Good afternoon friends! The task is to find common words in two lines, that is:
checkio("hello,world", "hello,earth") == "hello" or
checkio("one,two,three", "four,five,six") == "" I wrote the code to solve this problem. Please judge STRICTLY. This code is not validated.
def checkio(first, second): list_one = first.split(',') list_two = second.split(',') list_new = [] for word in list_one: if word in list_two: list_new.append(word) return list_new 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" The code does not pass, because the list is returned in the form ['hello'] , and the return is expected in the form of "hello" .
I understand that my question is most likely absolutely basic, but alas, I cannot find an answer to it, I ask for your help.
Also, please show me how you can “in a normal way” write these lines of code (I am sure that you can write them humanly, and not like mine):
list_one = first.split(',') list_two = second.split(',') and
for word in list_one: if word in list_two: list_new.append(word) Thank you very much.
checkio('one,two,three', 'two,one')? - MaxU'hello'from['hello']? Where did you get the assert? (a specific link to checkio.org, if possible) Do you want to know the logic that explains why the answer is"one,three,two", and not the other five options? - jfs