I was given homework to write a Python program that allows the user to enter two sentences, and then puts the words of both sentences into a list in an interleaved fashion, and prints it, as in this example:
Sentence 1: Today I went to the beach
Sentence 2: Tomorrow I will travel to Europe
["Today", "Tomorrow", "I", "I", "went", "will", "to","travel", "the", "to", "beach", "Europe"]
I tried this, but dosen't work well with two phrases with diferent lenght
from itertools import cycle
list1=[]
list2=[]
phrase1=str(input("Enter phrase 1: "))
phrase2=str(input("Enter phrase 2: "))
list1=phrase1.split()
list2=phrase2.split()
print("The phrase 1 is: " + str(phrase1))
print("The phrase 2 is: " + str(phrase2))
res = [ele for comb in zip(lista1, lista2) for ele in comb]
print("Interleaved List : " + str(res))