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']
''?tempvariable astemp. It confused me for half of a minute what the program supposes to do. Renaming it to something like "previous_header" might help solving your problem in the first place. Although I am speaking from an observer point of view, naming variable is really important.