Answer the question
In order to leave comments, you need to log in
How to work with a string in python according to the principle of csv format?
You need to write a function that will take csv files or a csv style string and translate it into a dict.
There are no problems with the first one, since python has csv.DictReader.
class CSVParser:
def parse(self, data: str) -> list:
"""Parses input str data into dict."""
result = []
for row in csv.DictReader(data):
result.append(row)
return result
data = """
a, b, c
1, 2, 3
1.1, 2.2, 3.3
"""
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question