Monday, 19 August 2013

Assign elements of 2d list before integer > 1 (python)

Assign elements of 2d list before integer > 1 (python)

I want to make the preceding integers of a 2d list equal to a certain
integer which is greater than 1. So for example if I have the input:
L = [[1, 2, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 3, 1, 2, 1, 1, 1, 1]]
The desired output would be:
[[2, 2, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1], [3, 3, 3, 2, 2, 1, 1, 1, 1]]
Here the two preceding integers of the 3 have to be set equal to this 3,
and the one preceding integer of the 2 have to be set equal to this 2. Is
there a systematical way to do this in python?

No comments:

Post a Comment