I'm having trouble in removing some empty indexes from a list of lists. It was a list with letters and values, and I only needed the values, but some indexes of the list had only letters, and removing them left some empty indexes on my list.
Originally it was a list of strings with letters and numbers.
The list:
[['29882.09'],[],['81005.79'],[],['14700.0']]
And some of the solutions I tried, that either didn't change anything or gave me an entirely empty list.
This one, didn't change anything on the list:
list = [x for x in list if x != []]
This one didn't change anything either:
for item in list:
if item!=[]:
list2.append(item)
And this one just gave me back an entirely empty list:
for i in range(len(list)):
list[i] = list(filter(None, list[i]))
With those empty indexes, I can't use .append of openpyxl because it says the index is out of range.
The line that gives an error with the list with empty indexes:
ws.append({'A': list_names, 'B': list_values[0]})
wb.save('doc.xlsx')
And it gives me is "IndexError list index out of range".
This is part of code where I'm converting a PDF to XLSX (this is the part of the conversion code and the separation values to columns), to compare values from two different columns on different XLSXs and create a third one with the missing values. I can't just edit the code to skip certain indexes because I need it to work with other PDFs with the same model.
I found out why the code isn't working, apparently the empty brackets are considered to be on the same index as the index above, so the real list would be:
[['29882.09'][],['81005.79'][],['14700.0']]
I found this out by doing print(len(item)).
Is there a way to remove those empty brackets at the end?