-3

How i can convert a list of,

>> print(row)
>> [text:'Data 1', text:'Data 27']  # this is list but i want a dic

to something like

>> print(row)
>> {'text':'Data 1', 'text':'data 27'} # this is how i want my list to be

i tried like every possible aswer that i found while googling this.

this is what i got when i write print(type(row[0]))

enter image description here

this is my full code

import xlrd

def readData(xlsxfilename):
    workbook = xlrd.open_workbook(xlsxfilename, on_demand=True)

    # Getting the first sheet in the file which should contain input data
    worksheet = workbook.sheet_by_index(0)

    max_nb_row = 0
    max_nb_row = max(max_nb_row, worksheet.nrows)

    # Getting data
    i = 0
    for row in range(max_nb_row):
        if i is not 0:  # skip the first row because it just contains: Data Column 1 Data Column 2
            if row < worksheet.nrows:
                calcScore(worksheet.row(row))
        i += 1


# TODO: calculate the score
def calcScore(row):
    print(type(row[0]))
RoadieRich
  • 6,330
  • 3
  • 35
  • 52
Ayyoub
  • 4,581
  • 2
  • 19
  • 32

1 Answers1

0

from the comments, @PM2Ring suggested using this, and it worked like a charm

[c.value for c in row]

Ayyoub
  • 4,581
  • 2
  • 19
  • 32