Question
longest.py - finding the longest_lines in a file Please define a function longest_lines that takes in a filename, loads the file (try 'filename'.open().readlines()), computes the
longest.py - finding the longest_lines in a file Please define a function longest_lines that takes in a filename, loads the file (try 'filename'.open().readlines()), computes the length of the longest line, 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']. Hint 1: you can use max on a list. print(max([1,2,3,-2,-1])) Hint 2: if you define one function inside another, you can access the outer function's variables. Python lets you use lambda to define an anonymous function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started