Question: # For file with only numbers, you should only return one thing ( i . e . the first 1 0 characters ) # For

# For file with only numbers, you should only return one thing(i.e.the first 10 characters)
# For file with story,you NEED to return two things(i.e. a modified string AND a list)
# you can return multiple values by simply return them separated by commas like the following
# def editor(fname):
# return 'modifystring', [a,b,c,d]
# HINT: to call your function for the story.txt file, use the following command
# editor("./data/story.txt")
# return statement should be in the format below
# return 'modifystring', [a,b,c,d]
import re
from collections import Counter
def editor(fname):
Test Case 1:
import pytest
from week1 import editor
def test_story1():
new_text, top_five = editor('data/story.txt')
expected=['the','of','and','with','a']
assert set(top_five)==set(expected)
assert new_text =='''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 seven-foot 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.'''
Test Case 2:
import pytest
from week1 import editor
def test_story2():
new_text, top_five = editor('data/story2.txt')
expected =['is', 'better', 'than', 'to', 'the']
assert set(top_five)==set(expected)
assert new_text =='''beautiful is better than ugly.explicit is better than implicit.simple is better than complex.complex is better than complicated.flat is better than nested.sparse is better than dense.readability counts.special cases aren't special enough to break the rules.although practicality beats purity.errors should never pass silently.unless explicitly silenced.in the face of ambiguity, refuse the temptation to guess.there should be one-- and preferably only one --obvious way to do it.although that way may not be obvious at first unless you're dutch.now is better than never.although never is often better than *right* now.if the implementation is hard to explain, it's a bad idea.if the implementation is easy to explain, it may be a good idea.namespaces are one honking great idea -- let's do more of those!'''
The original text for text case 1 :
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 seven-foot 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.
The original text for test case 2:
Beautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than dense.Readability counts.Special cases aren't special enough to break the rules.Although practicality beats purity.Errors should never pass silently.Unless explicitly silenced.In the face of ambiguity, refuse the temptation to guess.There should be one-- and preferably only one --obvious way to do it.Although that way may not be obvious at first unless you're Dutch.Now is better than never.Although never is often better than *right* now.If the implementation is hard to explain, it's a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea -- let's do more of those!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!