Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python CSV code

Practice reading and writing CSV rows and using dictionary-based CSV access.

Intermediate ~8 min read

Challenge 1

Create a CSV reader for the open text stream.

python Your answer
import csv

rows = "name,score\nAda,10\n"
from io import StringIO
reader = 
print(list(reader))

Press Ctrl⌘Enter to check your answer

Challenge 2

Write one row to the CSV writer.

python Your answer
import csv
from io import StringIO

output = StringIO(newline="")
writer = csv.writer(output)

print(output.getvalue())

Press Ctrl⌘Enter to check your answer

Challenge 3

Create a dictionary-based CSV reader for the text stream.

python Your answer
import csv
from io import StringIO

data = "name,score\nAda,10\n"
reader = 
print(next(reader)["name"]) 

Press Ctrl⌘Enter to check your answer

Challenge 4

Read this semicolon-delimited data by specifying its delimiter.

python Your answer
import csv
from io import StringIO

data = "name;score\nAda;10\n"
reader = 
print(list(reader))

Press Ctrl⌘Enter to check your answer