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.
fname = input("Enter file name: ") fname = open("mbox-short.txt") counts = dict() emails = list() for line in fname: if not line.startswith('From ') : continue words = line.split() emails.append(words[1]) for email in emails: counts[email] = counts.get(email, 0) + 1 bigcount = None bigemail = None for email, count, in counts.items() : if bigcount is None or count > bigcount: bigemail = email bigcount = count print(bigemail, bigcount)
¿Quiéres el ejercicio resuelto en menos de 48 horas? Paga desde $US 4 (4 DÓLARES) vía PayPal o desde $ 10.000 pesos (colombianos) vía Nequi si estás en Colombia, comunicándote al whatsapp +573203806207 para confirmar pago, y tendrás el ejercicio resuelto.
7 comentarios en “Exercise 9.4 Python For Everybody”