How to Read a CSV into list of lists in Python

In this lesson we want to learn How to Read a CSV into list of lists in Python, Python is high level and general purpose programming language. It was first released in 1991 by Guido van Rossum.

Some of key features of Python include:

  • Easy-to-read syntax: Python has simple and clean syntax and makes it easy to learn and write code for both beginners and experienced programmers.
  • Dynamic Typing: Python uses dynamic typing, which means that you can assign values to variables without specifying their type. the type of variable is determined at runtime.
  • Object-Oriented Programming: Python is an object oriented programming language, which means that it supports the creation of objects, classes and methods to model realworld objects.
  • Large Standard Library: Python has large and comprehensive standard library that covers a wide range of tasks from web development to data analysis. this makes it easy to find and use pre written code for common tasks.
  • Interoperability: Python can work seamlessly with other programming languages, making it easy to integrate with existing codebases and to use it in a variety of applications.




You can use csv module in Python to read a CSV file into a list of lists.

This is an example code to do this:

In this example, file.csv is the name of the CSV file you want to read. with statement is used to open file and csv.reader function is used to create reader object that can be used to read the data from the file.

The list() function is then used to convert the reader object into list of lists, where each row of the CSV file is represented as a separate list, and finally print(data) statement is used to display the list of lists, which contains the data from the CSV file.




Learn More on Python


Leave a Comment