Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

240
Visualizações
Assemble multiple lists into a single list through a loop

As part of an application reading Csv files made using tkinder and the tksheet library, I would have liked to ensure that each of the lines retrieved from my spreadsheet and individually transformed into a list could be grouped into a single and unique comma separated list.

I currently have the following code:

with open('my_csv_file.csv') as csvfile:
     reader = csv.reader(csvfile, delimiter=';')
            
     for row in reader:
         if row != '' and row[0].isdigit():
            liste = [row[0], row[1], row[2], row[3], row[4]]
            print(liste)

Output :

['AAA', 'AAA', 'AAA', 'AAA', 'AAA']
['BBB', 'BBB', 'BBB', 'BBB', 'BBB']
['CCC', 'CCC', 'CCC', 'CCC', 'CCC']

What I want:

[['AAA', 'AAA', 'AAA', 'AAA', 'AAA'],
['BBB', 'BBB', 'BBB', 'BBB', 'BBB'],
['CCC', 'CCC', 'CCC', 'CCC', 'CCC']]
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

you can add list and append list in the list with list +=

with open('my_csv_file.csv') as csvfile:
     res = []
     reader = csv.reader(csvfile, delimiter=';')
            
     for row in reader:
         if row != '' and row[0].isdigit():
            res += [[row[0], row[1], row[2], row[3], row[4]]]
            

or you can use append

with open('my_csv_file.csv') as csvfile:
     res = []
     reader = csv.reader(csvfile, delimiter=';')
            
     for row in reader:
         if row != '' and row[0].isdigit():
            res.append([row[0], row[1], row[2], row[3], row[4]])
            
over 4 years ago · Santiago Trujillo Relatório

0

Append to the top list to make your nested list.

lst = []

with open('my_csv_file.csv') as csvfile:
     reader = csv.reader(csvfile, delimiter=';')
            
     for row in reader:
         if row != '' and row[0].isdigit():
            lst.append([row[0], row[1], row[2], row[3], row[4]])

print(lst)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda