GLOBAL AI

Fix Python loop reading sales.csv

  1. My loop prints only the first row of sales.csv. Why?

    29 Nov
  2. Your `return` sits inside the loop, so it exits after the first row. Move it out:

    import csv
    rows = []
    with open('sales.csv') as f:
        for row in csv.DictReader(f):
            rows.append(row)
    print(len(rows))
    
    29 Nov

Delete the chat "Fix Python loop reading sales.csv"?

Its 2 messages will be gone for good.

Photos from Pexels

Photos from Pexels

Built with BooDoo · Make yours