The Longest Review

Python for AIMedium+10 XP+10

The Longest Review

A café collects customer reviews in a CSV file. The owner wants to find the longest single value in it: the wordiest thing anyone wrote.

Task: write longest_value(path, text). It returns the longest value (the most characters) found in any data row, in any column.

  • Leave out the line of column names.
  • Values must be read properly with csv.reader, so a value like "great, really" is one value, without its quote marks.
  • If two values tie for longest, return the one that comes first, reading row by row, left to right.
  • If there are no data rows, return "".

The starter code includes a small helper, write_text, and already calls it for you: it saves text into a file named path. Your code then opens that file and reads it. import csv is already at the top of the starter code.

Examples

path = 'cafe.csv'
text = 'name,review\nada,"great, really"\nbo,nice\n'
returns 'great, really'
path = 'cafe2.csv'
text = 'name,review\nada,ok\nbo,fine\n'
returns 'fine'

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run