-1

Anyone knows how to create a xls file from a dict? I have a dictionary filled with words in a text, i want to put this DICT in a xls

def contar_Repetidas(texto):
    dic={}
    l=texto.split()
    for palabra in l:
        if palabra not in dic:
            dic[palabra] = 1
        else:
            dic[palabra] +=1
    return dic

It's diferent becorse, i want to create a MS Excel from a DICT, a DICT

Guillermo
  • 327
  • 2
  • 6
  • 20

1 Answers1

2

Using the xlwt module:

import xlwt

dic = contar_Repetidas("Some Text Here")

wb = xlwt.Workbook()
ws = wb.add_sheet("Your Sheet")

count = 0
for word, num in dic.items():
    count += 1
    ws.write(count, 1, word)
    ws.write(count, 2, num)

wb.save("/Path/To/Save/Example.xls")
scohe001
  • 15,110
  • 2
  • 31
  • 51