Question: Write a function in pure python to parse CSV data and return a 2 D array - the output format must match what is expected

Write a function in pure python to parse CSV data and return a 2D array - the output format must match what is expected by the automated test:
def my_csv_parser(csv_data, sep):
res =[]
lines = csv_data.split("\
")
for line in lines:
line = line.strip()
line = line.split(sep)
",".join(line)
res.append(line)
return res
# input: "a,b,c,e\
1,2,3,4\
"
# expected return: [["a","b","c","e"],["1","2","3","4"]]
# actual return out: [["a","b","c","e"],["1","2","3","4"],[""]]
# note the lack of spaces between elements and subarray; and the extra subarray

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!