Hello,
I would like to add every element of a list on every list from a list of lists. Ie :
Ie :
Can you help me please to solve my problem ?
I would like to add every element of a list on every list from a list of lists. Ie :
H = [[1,2],[3,4]] I = [5,6]With this result :
Output:J = [[1,2,5], [3,4,5], [1,2,6], [3,4,6]]
I don’t find the good logic.Ie :
j = [] for x in h : for y in i : j.append(h+i) print (j)Gives me :
Output:[[[1, 2], [3, 4], 5, 6]]
[[[1, 2], [3, 4], 5, 6], [[1, 2], [3, 4], 5, 6]]
[[[1, 2], [3, 4], 5, 6], [[1, 2], [3, 4], 5, 6], [[1, 2], [3, 4], 5, 6]]
[[[1, 2], [3, 4], 5, 6], [[1, 2], [3, 4], 5, 6], [[1, 2], [3, 4], 5, 6], [[1, 2], [3, 4], 5, 6]]
Or again :k = [] for w in h : for z in i : o = [w,z] k.append(o) print (k)Will give :
Output:[[[1, 2], 5]]
[[[1, 2], 5], [[1, 2], 6]]
[[[1, 2], 5], [[1, 2], 6], [[3, 4], 5]]
[[[1, 2], 5], [[1, 2], 6], [[3, 4], 5], [[3, 4], 6]]
I’ve tried some tests with map, but nothing conclusive.Can you help me please to solve my problem ?