tags:

views:

61

answers:

4

i have a list of a list:

b=[[1,2,3],[4,5,6],[7,8,9]]

i have a list:

row = [1,2,3]

how do i append to b only row[0] and '3847' and row[2] such that b will equal:

b=[[1,2,3],[4,5,6],[7,8,9],[1,3847,3]]
+3  A: 

You're going to have to be more specific.

This will accomplish what you want:

b.append([row[0], 3847, row[2]])

But isn't really a general solution.

Nick Presta
+1  A: 
b.append([ x if x != 2 else 3847 for x in row])
sje397
+1  A: 
b + [[row[0],3847,row[2]]]
ghostdog74
I think you mean, `b + [[row[0], 3242, row[2]]]`
aaronasterling
To append the data they'd need `b = b + [[row[0],3847,row[2]]]`.
martineau
A: 

b + [row[0],3847,row[2]] would give you:

>>> b + [row[0],3847,row[2]]
[[1, 2, 3], [4, 5, 6], [7, 8, 9], 1, 3847, 3]

In order to get b=[[1,2,3],[4,5,6],[7,8,9],[1,3847,3]], you need to use append as suggested by "Nick Presta". You may have received other suitable solutions if you made the problem statement clearer.

Babil