Question

make a python dictionary that counts the number of times each letter occurs in the the...

make a python dictionary that counts the number of times each letter occurs in the the book below

book_url = 'http://www.gutenberg.org/cache/epub/2680/pg2680.txt'

Homework Answers

Answer #1

Here is the python code to do so. Before looking at the code you must know that in the code below I have only counted the frequency of English letters only. Here I have initialized the dictionary and incremented the respective key-value  as I found a letter.

import urllib.request
url = "http://www.gutenberg.org/cache/epub/2680/pg2680.txt"
file = urllib.request.urlopen(url)

letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
freqMap = {}
for letter in letters:
    freqMap[letter] = 0
for line in file:
    decoded_line = line.decode("utf-8")
    for i in decoded_line:
        if i in freqMap:
            freqMap[i] = freqMap[i]+1

print("Count of all the letters present are: ")
print(freqMap)
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The language of code in C#. Finds the number of times a word occurs by itself...
The language of code in C#. Finds the number of times a word occurs by itself (as a complete word) or as part of another word in the given "wordFragment" substring. For example in the string "The bon in bonbon", we count 2 occurrences of bon. Please write a simple code without the use of advanced features such as LINQ. It's recommended using the Dictionary feature. Returns the number of times wordFragment occurs in the file that WordCounter is associated...
python program on sonnets to Count the occurrences of each letter in the text.,. Print the...
python program on sonnets to Count the occurrences of each letter in the text.,. Print the number of one-letter, two-letter, three-letter words and so on. and Print the number of occurrences of each different word in the text using  the text from the sonnets.txt file and apply these three metrics
Roll a die 8 times. Compute the probability that a number occurs 6 times and two...
Roll a die 8 times. Compute the probability that a number occurs 6 times and two other numbers occur 1 time each.
Write a python program that will perform text analysis on an input text using all of...
Write a python program that will perform text analysis on an input text using all of the following steps: 1. Take the name of an input file as a command line argument. For example, your program might be called using python3 freq.py example1 to direct you to process a plain text file called example. More information is given on how to do this below. 2. Read the contents of the file into your program and divide the text into a...
8) Write Python code for a function called occurances that takes two arguments str1 and str2,...
8) Write Python code for a function called occurances that takes two arguments str1 and str2, assumed to be strings, and returns a dictionary where the keys are the characters in str2. For each character key, the value associated with that key must be either the string ‘‘none’’, ‘‘once’’, or ‘‘more than once’’, depending on how many times that character occurs in str1. In other words, the function roughly keeps track of how many times each character in str1 occurs...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may be given a list of raw email addresses and be asked to generate meaningful information from such a list. This project involves parsing such a list and generating names and summary information from that list. The script, eparser.py, should: Open the file specified as the first argument to the script (see below) Read the file one line at a time (i.e., for line in...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT