The Biggest File

Python for AIMedium+10 XP+10

The Biggest File

You have a few saved essays and want to find the longest one.

Write longest_file(paths). paths is a list of file names. Read each file and return the name of the file that holds the most characters.

  • If two or more files tie for the most, return the one that comes first in paths.
  • paths always has at least one name in it.
  • Use with to open each file.

The starter has a make_file(path, text) helper that creates test files. Leave it as it is.

Examples

paths = [make_file('a.txt', 'hi'), make_file('b.txt', 'hello'), make_file('c.txt', 'hey')]
returns 'b.txt'
paths = [make_file("lf_a1.txt", "short"), make_file("lf_a2.txt", "much longer text")]
returns 'lf_a2.txt'
paths = [make_file("lf_b1.txt", "same"), make_file("lf_b2.txt", "size")]
returns 'lf_b1.txt'

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