Use csv.DictReader
:
import csv
with open('test.csv') as f:
a = [{k: int(v) for k, v in row.items()}
for row in csv.DictReader(f, skipinitialspace=True)]
Will result in :
[{'col2': 2, 'col3': 3, 'col1': 1}, {'col2': 5, 'col3': 6, 'col1': 4}]
Related Contents:
- How do I sort a list of dictionaries by a value of the dictionary?
- How do I convert two lists into a dictionary?
- Access nested dictionary items via a list of keys?
- Getting a list of values from a list of dicts
- Creating a dictionary from a csv file?
- How can I get list of values from dict?
- How do I merge a list of dicts into a single dict?
- Dictionary: Get list of values for list of keys
- Access a particular field in arbitrarily nested JSON data [duplicate]
- How to return dictionary keys as a list in Python?
- How do I convert this list of dictionaries to a csv file?
- Create a list with initial capacity in Python
- Pandas DataFrame to List of Dictionaries
- Creating a list of dictionaries results in a list of copies of the same dictionary
- In Python, when to use a Dictionary, List or Set?
- How can I convert a dictionary into a list of tuples?
- How to overcome TypeError: unhashable type: ‘list’
- Writing a dictionary to a csv file with one line for every ‘key: value’
- List of dicts to/from dict of lists
- Creating a dictionary from a CSV file
- python filter list of dictionaries based on key value
- How do I combine two lists into a dictionary in Python? [duplicate]
- Converting list of tuples into a dictionary
- Converting Dictionary to List? [duplicate]
- How to find the min/max value of a common key in a list of dicts?
- join two lists of dictionaries on a single key
- How can I access the nested data in this complex JSON, which includes another JSON document as one of the strings?
- List of tuples to dictionary [duplicate]
- Write dictionary of lists to a CSV file
- Check if value already exists within list of dictionaries?
- Appending a dictionary to a list in a loop
- Sorting a dictionary with lists as values, according to an element from the list
- Python Dictionary to CSV
- How can I make a dictionary (dict) from separate lists of keys and values?
- Combining Dictionaries Of Lists In Python
- How do I sort this list in Python, if my date is in a String?
- Most Pythonic Way to Build Dictionary From Single List
- Get a list of values from a list of dictionaries?
- Why can’t I use a list as a dict key in python? Exactly what can and cannot be used, and why?
- How do I return dictionary keys as a list in Python?
- How can I avoid “RuntimeError: dictionary changed size during iteration” error?
- Setting a value in a nested Python dictionary given a list of indices and value
- Group by multiple keys and summarize/average values of a list of dictionaries
- Convert list of strings to dictionary
- Changing one dict changes all dicts in a list of dicts [duplicate]
- Make dictionary from list with python [duplicate]
- Using a dict to translate numbers to letters in python
- Why does CSV file contain a blank line in between each data line when outputting with Dictwriter in Python [duplicate]
- Comparing 2 lists consisting of dictionaries with unique keys in python
- How to sort a list of dictionaries by a value of the dictionary in Python?