sebap123
sebap123

Reputation: 2685

Adding extra column in the middle of the row while appending it in list

I am trying to find some answer, but all I found is not regarding my problem. Can someone please tell me how I can append row into other row at the same time adding some extra column?

So far I have something like this:

for row in reader_action[0]:
    action_res.append([row[0:2],0,row[2:]])

and the output is:

[['1', '2'], 0, ['3', '4', '5']]

but what I am looking for is:

['1', '2', 0, '3', '4', '5']

Upvotes: 0

Views: 53

Answers (1)

Brian
Brian

Reputation: 2242

From your description, I think you want:

for row in reader_action[0]:
    action_res.append([row[0:2] + [0] + row[2:]])

Upvotes: 2

Related Questions