Hello,
I would like to add every element of a list on every list from a list of lists. Ie :
With this result :
Ie :
Gives me :
Will give :
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 :
1 2 |
H = [[ 1 , 2 ],[ 3 , 4 ]] I = [ 5 , 6 ] |
Output:J = [[1,2,5], [3,4,5], [1,2,6], [3,4,6]]
I don’t find the good logic.Ie :
1 2 3 4 5 |
j = [] for x in h : for y in i : j.append(h + i) print (j) |
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 :1 2 3 4 5 6 |
k = [] for w in h : for z in i : o = [w,z] k.append(o) print (k) |
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 ?