Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a CSV file scores.csv with the header name,score and the rows Asha,72 and Rao, Ravi,85 (the name of the second student holds a comma). Read it back with the csv module, and show the two rows.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Use csv.writer with newline="". The writer puts quotation marks around the name that holds a comma.
Check. The file holds name,score, Asha,72 and "Rao, Ravi",85. The reader gives back ['name', 'score'], ['Asha', '72'] and ['Rao, Ravi', '85']. The comma inside the name did not make a new column, and the numbers came back as texts.
Answer: The three rows above, with Rao, Ravi kept as one name.
Log in to join the discussion.
Loading…