I know there is a bunch of similar answers here but I tried at least 10 of them and did not work in my case since it also involves splitting the list and adding string...so any help is appreciated!
Write a function 'conjunctions' which recevies a nested list 'word_list'. This list contains a number of sublists, each a list of words (i.e. strings), such as:
[["Tom", "Laurel", "Merkel"], ["Jerry","Hardy", "Macron"]]
Note that all the sublists have the same number of words in them. Your function must return a list of strings, where each element in a position is an "and" conjunction of all the elements in the same position in all the sublists. For example:
conjunctions([["Tom", "Laurel", "Merkel"],["Jerry","Hardy", "Macron"]])
should return
['Tom and Jerry', 'Laurel and Hardy', 'Merkel and Macron']
and
conjunctions([["one", "apples"],["two","oranges"],["three","bananas"]])
should return:
['one and two and three', 'apples and oranges and bananas']
I spent hours but all I can do is to change the order of the elements but I don't know how to further concatenate them:
def conjunctions(word_list):
name = []
for word in word_list:
for length in range(len(word)):
for n in range(len(word_list)):
name.append(word_list[n][length])
return name
this will only return me a list like this (using example two):
['one', 'two', 'three', 'apples', 'oranges', 'bananas']
Thank you in advance for your help!