I'm new to python and I have to change this code to have a 1D array not a 2D array.This code is perfectly working to write data to an excel file. Please help me to change this in to a 1D array.
eg: only to enter as 1D array as below
expenses = [
[1000],
[100],
[300],
[50],
]
import xlsxwriternter
workbook = xlsxwriter.Workbook('20.xlsx')
worksheet = workbook.add_worksheet()
expenses = [
['Rent', 1000],
['Gas', 100],
['Food', 300],
['Gym', 50],
]
row = 0
col = 0
for item,cost in (expenses):
worksheet.write(row, col, item)
row += 1
workbook.close()
rowso it is placing the items in rows, if you instead incrementedcolit would write to separate columns...expenseslist? that would be easy, just changefor item,cost in (expenses):tofor item, in (expenses):so that you are unpacking only one item and not two.for item, in...this means you are unpacking a single element from the list, either that or you dofor item in expenses:thing_to_write = item[0]