Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Define a function called letters that takes a string called text and returns a dictionary. The dictionary should have 26 keys -- one for

1. Define a function called letters that takes a string called text and returns a dictionary. The dictionary should have 26 keys -- one for each letter of the alphabet (count 'a' and "A" both as occurrences of 'a') -- and the value for each key should be the number of times that letter appears in the text.

2. Write a program that calls letters on the following encrypted text file: encrypted.txt (or use this version for mac).

3. Edit your letters function so that it returns a string (or a list) sorted by how often the letter appears, in decreasing order. For example, if 'k' appeared most, and then 'x', your returned string should start "kx..." (or, if it's a list, ['k', 'x', ... ]).

TEXT FILE CONTENTS IS BELOW

"d vh ocz ompz qdiz, viy ht avoczm dn ocz bvmyzizm. cz xpon jaa zqzmt wmvixc di hz ocvo wzvmn ij ampdo, rcdgz zqzmt wmvixc ocvo yjzn wzvm ampdo cz kmpizn nj ocvo do rdgg wz zqzi hjmz ampdoapg. tjp vmz vgmzvyt xgzvi wzxvpnz ja ocz rjmy d cvqz nkjfzi oj tjp. mzhvdi di hz, vn d vgnj mzhvdi di tjp. ij wmvixc xvi wzvm ampdo wt donzga; do hpno mzhvdi di ocz qdiz. izdoczm xvi tjp wzvm ampdo pigznn tjp mzhvdi di hz." d vh ocz qdiz; tjp vmz ocz wmvixczn. da tjp mzhvdi di hz viy d di tjp, tjp rdgg wzvm hpxc ampdo; vkvmo amjh hz tjp xvi yj ijocdib. da tjp yj ijo mzhvdi di hz, tjp vmz gdfz v wmvixc ocvo dn ocmjri vrvt viy rdoczmn; npxc wmvixczn vmz kdxfzy pk, ocmjri dioj ocz admz viy wpmizy. da tjp mzhvdi di hz viy ht rjmyn mzhvdi di tjp, vnf rcvozqzm tjp rdnc, viy do rdgg wz yjiz ajm tjp. ocdn dn oj ht avoczmn bgjmt, ocvo tjp wzvm hpxc ampdo, ncjrdib tjpmnzgqzn oj wz ht ydnxdkgzn." vn ocz avoczm cvn gjqzy hz, nj cvqz d gjqzy tjp. ijr mzhvdi di ht gjqz. da tjp fzzk ht xjhhviyn, tjp rdgg mzhvdi di ht gjqz, epno vn d cvqz fzko ht avoczmn xjhhviyn viy mzhvdi di cdn gjqz. d cvqz ojgy tjp ocdn nj ocvo ht ejt hvt wz di tjp viy ocvo tjpm ejt hvt wz xjhkgzoz. ht xjhhviy dn ocdn: gjqz zvxc joczm vn d cvqz gjqzy tjp. bmzvozm gjqz cvn ij jiz ocvi ocdn: oj gvt yjri jizn gdaz ajm jizn amdziyn. tjp vmz ht amdziyn da tjp yj rcvo d xjhhviy. d ij gjibzm xvgg tjp nzmqvion, wzxvpnz v nzmqvio yjzn ijo fijr cdn hvnozmn wpndiznn. dinozvy, d cvqz xvggzy tjp amdziyn, ajm zqzmtocdib ocvo d gzvmizy amjh ht avoczm d cvqz hvyz fijri oj tjp. tjp ydy ijo xcjjnz hz, wpo d xcjnz tjp viy vkkjdiozy tjp nj ocvo tjp hdbco bj viy wzvm ampdoampdo ocvo rdgg gvnoviy nj ocvo rcvozqzm tjp vnf di ht ivhz ocz avoczm rdgg bdqz tjp. ocdn dn ht xjhhviy: gjqz zvxc joczm."

MUST BE ABLE TO COPY AND PASTE INTO PYTHON AND IT RUN PERFECTLY

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

Students also viewed these Databases questions