Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def g(input, offset=0):
- return [sum(input[:i+1]) + offset if x else None for i, x in enumerate(input)]
- def f(input, offset_carry=0):
- # ~~ recursive ~~
- # base case:
- if not input:
- return []
- # recursive case:
- current = input[0]
- current_sum = sum(current)
- # e.g. [[1, 2, None]] + [[3, None], [None, 4, 5]]
- return [g(current, offset_carry)] + f(input[1:], offset_carry + current_sum)
- wow = [[True, False, True, True], [False, False, False, True]]
- print(f(wow))
- # prints:
- # [[1, None, 2, 3], [None, None, None, 4]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement