What is the best way in Python to perform a merge where the value is not 0, resulting in the following outcome?
list = [
[0, 0, 0, '', 0, 0, 0, 0, 0],
[0, 0, 0, 0, 'b', 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 'c', 0, 0],
[0, 0, 0, 0, 0, 0, 0, '', 0],
[0, 0, 0, 0, 0, 0, 0, 0, '']
]
[[0, 0, 0, '', 'b', 0, 'c', '', '']] # result
>Solution :
You can filter 0s from the sublists transposed with zip:
[next((i for i in s if i != 0), 0) for s in zip(*lst)]
Demo: https://ideone.com/brrPH3