Anonymous function practice

Anonymous function practice#

Please define a function longest_lines that takes in a filename and returns all of the lines in that file of that length.

For example, if we have a file foo.txt:

a
b
cd
ef
g

Running longest_lines('foo.txt') will return ['cd', 'ef']. Try to do it using map, filter, and lambda.

Hint 1: you can use max on a list.

Hint 2: if you define one function inside another, you can access the outer function’s variables.