Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda