-
-
Save MichelleDalalJian/0f7d3e76535142aa52377a1d48ff0600 to your computer and use it in GitHub Desktop.
fname = input("Enter file:") | |
if len(fname) < 1 : name = "mbox-short.txt" | |
hand = open(fname) | |
lst = list() | |
for line in hand: | |
if not line.startswith("From:"): continue | |
line = line.split() | |
lst.append(line[1]) | |
counts = dict() | |
for word in lst: | |
counts[word] = counts.get(word,0) + 1 | |
bigcount = None | |
bigword = None | |
for word,count in counts.items(): | |
if bigcount is None or count > bigcount: | |
bigcount = count | |
bigword = word | |
print (bigword,bigcount) |
KarenTheEarth
commented
Apr 6, 2023
name = input("Enter file:")
handle = open(name)
leest = list()
for line in handle:
if line.startswith('From '):
line2=line.strip()
line3=line2.split()
line4=line3[1]
leest.append(line4)
#print(line4)
#print(leest)
dct = dict()
for email in leest:
dct[email] = dct.get(email,0) + 1
#print(dct)
dct_items = dct.items()
#print(dct_items)
coutmail = None
countcount = None
for K,V in dct_items:
if countcount is None or V>countcount:
countmail=K
countcount=V
print(countmail,countcount)
This is mine:
name = input("Enter file:")
handle = open(name)
counts = dict()
for line in handle:
if line.startswith('From:'):
words = line.split()
word = words[1]
else: continue
counts[word] = counts.get(word, 0) + 1
bigcount = None
bigword = None
for aaa, bbb in counts.items():
if bigcount is None or bbb > bigcount:
bigcount = bbb
bigword = aaa
print('The most sender is' , bigword,'with this number --->' , bigcount)
fname = input("Enter file:")
if len(fname) < 1 : name = "mbox-short.txt"
hand = open(fname)
lst = list()
for line in hand:
if not line.startswith("From:"): continue
line = line.split()
lst.append(line[1])
counts = dict()
for word in lst:
counts[word] = counts.get(word,0) + 1
bigcount = None
bigword = None
for word,count in counts.items():
if bigcount is None or count > bigcount:
bigcount = count
bigword = word
print (bigword,bigcount)
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name, "r")
counts = dict()
big_value = None
big_Key = None
for line in handle:
if line.startswith("From:"):
words = line.split()
word = words[1]
word = word.strip()
counts[word] = counts.get(word, 0) + 1
#print(counts)
for key, value in counts.items():
if big_value is None or big_value < value:
big_key = key
big_value = value
print(big_key,big_value)