a = [0, -4, 4, 6, 2, 5, 8]
b = [5, None, 3, None, 3, 2, 0]
c = [5, -4, 3, 6, 3, 2, 0]
I want to take a and b as inputs and get c, ideally using a list comprehension. Obviously I could iterate through this with a loop, but I’m wondering if there is a more elegant/pythonic solution.
>Solution :
this should work:
c = [value if value is not None else a[index] for index, value in enumerate(b)]