I'm going to write a program that takes some lines and translates them into one line but unfortunately, I have a problem with appending uncommon elements. this is what I've done so far:
List_of_sentences = []
for line in range(int(input())):
List_of_sentences.append(input().strip().split())
Sample_sentence = input().split()
Final_list = []
for lists in List_of_sentences:
for elements in Sample_sentence:
if elements in lists:
Final_list.append(lists[0])
else:
Final_list.append(elements)
print(' '.join(Final_list))
for example, consider these two lists:
List_of_sentences = [['man', 'I', 'je', 'ich'], ['kheili', 'very', 'très', 'sehr'], ['alaghemand', 'interested', 'intéressé', 'interessiert'], ['barnamenevisi', 'programming', 'laprogrammation', 'Programmierung']]
Sample_sentence = ['I', 'am', 'very', 'interested', 'in', 'programming']
it has to return this:
man am kheili alaghemand in barnamenevisi
but instead:
man kheili alaghemand barnamenevisi
my problem is with else part
any help is highly appreciated
question from:
https://stackoverflow.com/questions/65847866/append-on-condition 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…