How to generate lists by naming an item from another list?

0

It is a program that reads Excel spreadsheet with debit and credit postings in an account.

abreexcel2.py

def leplanilha():
   wb1 = oxl.load_workbook('extratomar2018.xlsx')
   folhas=wb1.get_sheet_names()
   print(folhas)
   sheet=wb1.get_sheet_by_name('plan1')
   nr=sheet.max_row
   nc=sheet.max_column
   for rw in range(2,nr+1):
      if sheet['D'+str(rw)].value in lista:
         pass
      else:
         lista.append(sheet['D'+str(rw)].value)
   print(lista)
leplanilha():

Generated the following list:

  

PAG BOLETO ',' SEND TEV ',' DEP CH 24H ',' CRED TED ',' RESG POUP ',' DOC ELET E ',' DEB BASKET ',' CHEQ COMP ',' GAS ']

Question: I would like to generate a list automatically, naming each of these elements of this list, to fill them, with the respective postings, but I can not.

How to generate a variable named after an item in a list?

    
asked by anonymous 10.04.2018 / 16:23

1 answer

0

If you want to create the lists with the name in the source code, then you need to create a file and print the new code with the names you want respecting the syntax of the language.

However, it is simpler to use a dictionary variable, where each name will be a key to a list, for example:

>>> nome_lista = 'SAQUE ATM'
>>> dicionario = {}
>>> dicionario[nome_lista] = [1,2,3]
>>> print (dicionario['SAQUE ATM'])
[1, 2, 3]
    
10.04.2018 / 16:53