Keeping the structure of a list in after operating a nested loop

Suppose I have two lists as follow: x = [[‘a’,’b’,’c’],[‘e’,’f’]] y = [‘w’,’x’,’y’] I want to add each element of list x with each element of list y while keeping the structure as given in x the desired output should be like: [[‘aw’,’ax’,’ay’,’bw’,’bx’,’by’,’cw’,’cx’,’cy’],[‘ew’,’ex’,’ey’,’fw’,’fx’,’fy’]] So far I’ve done: res = [] for i in range(len(x)): for… Read More Keeping the structure of a list in after operating a nested loop

Multiplying a list of integer with a list of string

Suppose there are two lists: l1 = [2,2,3] l2 = [‘a’,’b’,’c’] I wonder how one finds the product of the two such that the output would be: #output: [‘a’,’a’,’b’,’b’,’c’,’c’,’c’] if I do: l3 = [] for i in l2: for j in l1: l3.append(i) I get: [‘a’, ‘a’, ‘a’, ‘b’, ‘b’, ‘b’, ‘c’, ‘c’, ‘c’]… Read More Multiplying a list of integer with a list of string