I am working on a python code I have used temp variable because If there is any content present, that will be appended to temp variable and then it will be appended to header.
and if there is no content then temp variable will be appended.
so, it will restrict to append ” values to the list.
I am looking for any other finer method to get the same result but not using temp variable.
Any suggestions will be helpful.
temp = ''
header = []
for ind,content in enumerate(data): # enumerating for index & content in data
if content and ind != 0:
temp = content
header.append(content)
else:
header.append(temp)
input :
['column1', '', '', '', 'column2', '', '']
expected output :
['column1', 'column1', 'column1', 'column1', 'column2', 'column2', 'column2']
You can try something like this
Note** I have updated the answer to as not to update the original list.