Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help to modify the code to pass the test case: # For file with only numbers, you should only return one thing ( i
Please help to modify the code to pass the test case:
# For file with only numbers, you should only return one thingiethe first characters
# For file with story,you NEED to return two thingsie a modified string AND a list
# you can return multiple values by simply return them separated by commas like the following
# def editorfname:
#
# return 'modifystring', abcd
# HINT: to call your function for the story.txt file, use the following command
# editordatastorytxt
# return statement should be in the format below
# return 'modifystring', abcd
import re
from collections import Counter
def editorfname:
with openfnamer as file:
content file.readstrip
if content.isdigit:
return content:
else:
words content.split
modifiedwords wordcapitalize for word in words
modifiedstring joinmodifiedwords
wordcounts Counterwordlower for word in words
topfive word for word, count in wordcounts.mostcommon
return modifiedstring, topfive
Test Case :
import pytest
from week import editor
## dont change anything!!!
def teststory:
newtext, topfive editordatastorytxt
expectedtheof'and','with',a
assert settopfivesetexpected
assert newtext the man and his wife,
talking of the latest armed robbery in the suburb, were distracted by the sight of the little boy's pet cat
effortlessly arriving over the sevenfoot wall,
descending first with a rapid bracing of extended forepaws down on the sheer vertical surface,
and then a graceful launch, landing with swishing tail within the property.
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