CSV and JSON files · 7 / 15 Exercise Medium

Quoted fields

Objective

Create a Python program that reads CSV lines whose fields may contain commas, thanks to the quotes.

Instructions

  • Read an integer n and then n lines with the format name,"city, country",age. The second field is in quotes because it contains a comma.
  • Process the lines with csv.reader, which knows how to interpret the quotes.
  • For each line show name lives in city, country.
  • If you had used split(","), the field would have been cut in two: that is the advantage of the csv module.
Input
2
Ana,"Madrid, España",30
Luis,"Lyon, Francia",25
Output
Ana lives in Madrid, España
Luis lives in Lyon, Francia

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise