Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!