Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using python write the function count_letters in the code provided. It takes a string and returns a list of 26 integers being the count of

Using python write the function count_letters in the code provided. It takes a string and returns a list of 26 integers being the count of how many times the corresponding letter of the alphabet occurs in the string. Don't forget to add some more tests to the test suite. Is there anything interesting about the frequencies in olde English as opposed to modern English? (from the introduction to Chaucer's Canterbury Tales) Print a table of the frequencies consisting of 3 columns - letter of the alphabet, frequency in olde English, frequency in modern English

import sys def count_letters(s): """Return the frequency of each letter in string s. Return a list of frequency values (26 of them). Only count letters of the alphabet.""" # # ============================================================================ # Test suite - do not change anything between this and the next marker comment # lines. # Functions for unit testing of function # def print_test(did_pass): ''' print particular test result''' linenum = sys._getframe(1).f_lineno if did_pass: print('Test at line '+str(linenum)+' ok.') else: print('Test at line '+str(linenum)+' FAILED.') def test_suite(): ''' test the least_common_factor function ''' # # this is simply to help construct the list a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z # of frequencies you expect for the test # print_test(count_letters("hello") == [0,0,0,0,1,0,0,1,0,0,0,2,0,0,1,0,0,0,0,0,0,0,0,0,0,0]) print_test(count_letters("HELLO") == [0,0,0,0,1,0,0,1,0,0,0,2,0,0,1,0,0,0,0,0,0,0,0,0,0,0]) print_test(count_letters("It works!") == [0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,1,1,1,0,0,1,0,0,0]) # Add more calls to properly test the function. # ========================================================================= # # Main # test_suite() olde = """Here bygynneth the Book of the tales of Caunterbury Whan that aprill with his shoures soote The droghte of march hath perced to the roote, And bathed every veyne in swich licour Of which vertu engendred is the flour; Whan zephirus eek with his sweete breeth Inspired hath in every holt and heeth Tendre croppes, and the yonge sonne Hath in the ram his halve cours yronne, And smale foweles maken melodye, That slepen al the nyght with open ye (so priketh hem nature in hir corages); Thanne longen folk to goon on pilgrimages, And palmeres for to seken straunge strondes, To ferne halwes, kowthe in sondry londes; And specially from every shires ende Of engelond to caunterbury they wende, The hooly blisful martir for to seke, That hem hath holpen whan that they were seeke. Bifil that in that seson on a day, In southwerk at the tabard as I lay Redy to wenden on my pilgrymage To caunterbury with ful devout corage, At nyght was come into that hostelrye Wel nyne and twenty in a compaignye, Of sondry folk, by aventure yfalle In felaweshipe, and pilgrimes were they alle, That toward caunterbury wolden ryde. The chambres and the stables weren wyde, And wel we weren esed atte beste. And shortly, whan the sonne was to reste, So hadde I spoken with hem everichon That I was of hir felaweshipe anon, And made forward erly for to ryse, To take oure wey ther as I yow devyse. But nathelees, whil I have tyme and space, Er that I ferther in this tale pace, Me thynketh it acordaunt to resoun To telle yow al the condicioun Of ech of hem, so as it semed me, And whiche they weren, and of what degree, And eek in what array that they were inne; And at a knyght than wol I first bigynne.""" new = """Here begins the Book of the Tales of Canterbury When April with his showers sweet with fruit The drought of March has pierced unto the root And bathed each vein with liquor that has power To generate therein and sire the flower; When Zephyr also has, with his sweet breath, Quickened again, in every holt and heath, The tender shoots and buds, and the young sun Into the Ram one half his course has run, And many little birds make melody That sleep through all the night with open eye (So Nature pricks them on to ramp and rage)- Then do folk long to go on pilgrimage, And palmers to go seeking out strange strands, To distant shrines well known in sundry lands. And specially from every shire's end Of England they to Canterbury wend, The holy blessed martyr there to seek Who helped them when they lay so ill and weal Befell that, in that season, on a day In Southwark, at the Tabard, as I lay Ready to start upon my pilgrimage To Canterbury, full of devout homage, There came at nightfall to that hostelry Some nine and twenty in a company Of sundry persons who had chanced to fall In fellowship, and pilgrims were they all That toward Canterbury town would ride. The rooms and stables spacious were and wide, And well we there were eased, and of the best. And briefly, when the sun had gone to rest, So had I spoken with them, every one, That I was of their fellowship anon, And made agreement that we'd early rise To take the road, as you I will apprise. But none the less, whilst I have time and space, Before yet farther in this tale I pace, It seems to me accordant with reason To inform you of the state of every one Of all of these, as it appeared to me, And who they were, and what was their degree, And even how arrayed there at the inn; And with a knight thus will I first begin.""" 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

Students also viewed these Databases questions