9.4 Write a program to read through the mbox-short.txt and figure out who has sent the greatest number of mail messages. The program looks for 'From ' lines and takes the second word of those lines as the person who sent the mail. The program creates a Python dictionary that maps the sender's mail address to a count of the number of times they appear in the file. After the dictionary is produced, the program reads through the dictionary using a maximum loop to find the most prolific committer. 1 name = input("Enter file:") 2 if len(name) < 1 : name = "mbox-short.txt" 3 handle = open(name)
Answer:
file = raw_input("Enter file:")
if len(file) < 1:
name = "mbox-short.txt"
fh = open(name)
from_lines = []
emails = {}
for line in fh:
line = line.rstrip()
if line.find('From ') == 0:
line = line.split(' ')
email = line[1]
if email not in emails:
emails[email] = 1
else:
emails[email] += 1
email = ''
count = 0
for key in emails:
if emails[key] > count:
count = emails[key]
email = key
print "%s %s" % (email, str(count))
9.4 Write a program to read through the mbox-short.txt and figure out who has sent the...
7.2 Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475 Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum() function or a variable named sum in your solution. You can download the sample data at http://www.py4e.com/code3/mbox-short.txt when you are...
Python 12.10 LAB: Sorting TV Shows (dictionaries and lists)
Write a program that first reads in the name of an input file
and then reads the input file using the file.readlines() method.
The input file contains an unsorted list of number of seasons
followed by the corresponding TV show. Your program should put the
contents of the input file into a dictionary where the number of
seasons are the keys, and a list of TV shows are the values (since...
Write a program to read through the data stored in a file and when you find line that starts with “From”, split the line into words using the split function. We are interested in who sent the message, which is the second word on the From line. IN PYTHON
Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...
Pythong Program 4 should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file. Using try/except for...
Write a Python program named aIP.py which will read data from a file named wireShark.txt and extract all the pairs of source and destination ip addresses and output them in pairs to another file called IPAddresses.txt , one per line, listing source and destination. Example of output: Source Destination 192.168.1.180 239.255.255.250 Detailed Requirements: You will read from a file called wireShark.txt which, to avoid problems with finding paths, will be located in the same directory as your code You will...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...
Python Modify your recommendation program so that it reports the titles of the works rather than their file names. To do this, write a program that reads in the titles.txt file and creates a dictionary that looks up the title using the file name. This dictionary should then be used to report the works by their title instead of their file name. Script to use: import os import math def count_word(table, word): 'for the word entry in the table, increment...
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...