-
-
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) |
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
lst = list()
dic = dict()
for line in handle:
line = line.rstrip()
if not line.startswith("From: "): continue
words = line.split()
mail = words[1]
dic[mail] = dic.get(mail,0)+1
maxCount = max(dic.values())
for mail,count in dic.items():
if count == maxCount:
print(mail,count)
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
mydic=dict()
handle = open(name)
count=0
for line in handle:
lines=line.rstrip()
if lines.startswith('From:'):
continue
if lines.startswith('From'):
list=lines.split()
#print(list[1])
mydic[list[1]]=mydic.get(list[1],0)+1
#print(mydic)
maxval=max(mydic, key=mydic.get)
print(maxval,mydic[maxval])
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
dic = dict()
for line in handle:
wordsplit = line.split()
if 'From' in wordsplit:
email = wordsplit[1]
dic[email] = dic.get(email, 0) + 1
holder = 0
keyresult = None
valueresult = None
for key, value in dic.items():
if value > holder:
holder = value
keyresult = key
valueresult = value
print(keyresult, valueresult)
name = input("Enter file:")
handle = open(name)
a=None
big=dict()
for line in handle:
if line.startswith("From"):
line=line.split()
a=line[1:2]
for word in a:
big[word]= big.get(word,0)+1
bigcount=None
bigword=None
for word,big in big.items():
if bigcount is None or big > bigcount:
bigword=word
bigcount=big
print(bigword,bigcount)
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
counts= dict()
for line in handle:
if not line.startswith('From '):
continue
words= line.split()
email = words[1]
counts[email]=counts.get(email,0)+1
bigcount= None
bigword= None
for theword,count in counts.items():
if bigcount is None or count> bigcount:
bigword= theword
bigcount= count
print(bigword,bigcount)
name = "mbox-short.txt"
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
lst = list()
mail_names = list()
counts = dict()
qew= ""
for line in handle:
lst = line.rstrip().split()
if 'From' in lst:
mail_names.append(lst[1])
for name in mail_names:
counts[name] = counts.get(name, 0) + 1
max_name_as_list = [key for key, value in counts.items() if value == max(counts.values())]
max_name = qew.join(max_name_as_list)
print(max_name ,max(counts.values()))
fgh = input("Enter file:")
fh = open(fgh)
names = dict()
namelist = list()
for line in fh :
if not line.startswith("From ") : continue
name = line.split()
namelist.append(name[1])
for sendername in namelist :
names[sendername] = names.get(sendername,0) + 1
bigname = None
bigcount = None
for onename, onecount in names.items() :
if bigcount is None or onecount > bigcount:
bigcount = onecount
bigname = onename
print(bigname,bigcount)
file = input("Enter a file name : ")
fhand = open(file)
email = dict()
for line in fhand:
words = line.split()
if len(words) > 3 and words[0] == "From" :
email[words[1]] = email.get(words[1],0) + 1
else : continue
lst = list(email.values())
a =max(lst)
for i in email:
if email[i] == a:
print(i, email[i])
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name,'r')
counts=dict()
for line in handle:
if not line.startswith('From '): continue
words=line.split()
words=words[1]
counts[words]=counts.get(words,0)+1
bigword = None
bigcount = None
for word, count in counts.items():
if bigcount is None or count > bigcount:
bigword = word
bigcount = count
print(bigword, bigcount)
fname = input("Enter file name: ")
fh = open(fname)
counts = dict()
for line in fh:
if not line.startswith('From '):
continue #to skip the rest
else:
line = line.strip().split() #turns the line to a list
address = line[1] #get the senders email address
#creates a dictionary and gets how often a particular senders email appears
counts[address] = counts.get(address,0) + 1
bigword = None
bigcount = None
for word,count in counts.items():
if bigcount is None or count > bigcount:
bigword = word
bigcount = count
print(bigword,bigcount)
fname = input("Enter file name") fh = open(fname) counts = dict() lst = [] for line in fh: if not line.startswith("From "): continue line = line.rstrip().split() emails = line[1] lst.append(emails) for email in lst: counts[email] = counts.get(email, 0) +1 print(emails, counts[email])
hello bro. why output counts[email] are the largest.
.
this indicates the highest occurrence of that particular sender's email address
Is it because the list is automatically sorted? and which line indicates that?
u must separate the From: and From
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
dic=dict()
for line in handle:
if not line.startswith("From:"): continue
line = line.split()
if line[1] in dic.keys():
dic[line[1]]+=1
else:
dic[line[1]]=1
line=[]
largest=-1
for key,value in dic.items():
if largest< value:
largest=value
key_max=key
print(key_max,largest)
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
dic = {}
for line in handle:
line = line.rstrip().split()
if "From" in line:
key = line[1]
if key not in dic:
dic[key] = 1
else:
dic[key] += 1
value_list = []
for key, value in dic.items():
if value == max(dic.values()):
ans1 = key
ans2 = value
print(ans1, ans2)
fname = open("mbox-short.txt")
dtc = dict()
update_dtc = dict()
for line in fname:
if line.startswith("From "):
linea = line.strip().split()
if linea[1] in dtc:
update_dtc[linea[1]] = int(dtc.get(linea[1])) + 1
dtc.update(update_dtc)
else:
update_dtc[linea[1]] = 1
dtc.update(update_dtc)
max_value = max(dtc.values())
for element in dtc:
if dtc[element] == max_value:
correo = element
result = dtc.get(element)
print(str(correo) + " " + str(result))
name = input("Enter file:")
counts = dict()
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
for line in handle:
if line.startswith('From '):
words = line.split()[1]
counts[words] = counts.get(words,0) + 1
maxcount = None
maxword = None
for words,count in counts.items():
if maxcount is None or count > maxcount:
maxcount = count
maxword = words
print (maxword,maxcount)
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
db = list()
for word in handle:
word= word.strip()
if not word.startswith('From:'):
continue
word = word.split()
word = word[1]
db.append(word)
counts = dict()
for rows in db:
counts[rows] = counts.get(rows,0) + 1
max_count = None
max_word = None
for word, count in counts.items():
if max_count is None or count > max_count:
max_count = count
max_word = word
print(max_word,max_count)
Anyone knows why my code is not working? output is "[email protected] 10" instead of
"[email protected] 5". I think it is being double counted.
name = input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
lst = list()
for line in handle:
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
bigword = None
bigcount = None
for word,count in counts.items():
if bigcount is None or count > bigcount:
bigword = word
bigcount = count
print(bigword,bigcount)
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)
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
counts = dict()
for line in handle:
if line.startswith('From: '):
email = line[5:]
counts[email] = counts.get(email, 0) + 1
bigcount = None
bigemail = None
for email,count in counts.items():
if bigcount is None or count > bigcount:
bigcount = count
bigemail = email
print(bigemail,bigcount)