-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecord domain name.py
More file actions
67 lines (56 loc) · 1.6 KB
/
Record domain name.py
File metadata and controls
67 lines (56 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Write a program that records the domain name (instead of the
# address) where the message was sent from instead of who the mail came
# from (i.e., the whole email address). At the end of the program, print
# out the contents of your dictionary.
# python schoolcount.py
#
# RESULT :-
#
# Enter a file name: mbox-short.txt
# {'media.berkeley.edu': 4, 'uct.ac.za': 6, 'umich.edu': 7,
# 'gmail.com': 1, 'caret.cam.ac.uk': 1, 'iupui.edu': 8}
# CODE 1
newdict = dict()
newlist = list()
# file = input('Enter file name: ')
#
# try:
# ofile = open(file)
# except:
# print('File name not found. Please enter file name')
#
# for line in ofile:
# words = line. split()
# #print(words)
# if len(words) == 0 or words[0] != 'From':
# continue
# #print(words)
# #print(words[1])
# newlist.append(words[1])
# #print(newlist)
# for mail in newlist:
# pos = mail.find('@')
# domain = mail[pos + 1: ]
# #print(domain)
# newdict[domain] = newdict.get(domain, 0) + 1
# print(newdict)
# OR
file = input('Enter file name: ')
try:
ofile = open(file)
except:
print('File name not found. Please enter file name')
quit()
for line in ofile:
words = line. split()
#print(words)
if len(words) == 0 or words[0] != 'From':
continue
#print(words)
email = words[1]
#print(email)
pos = email.find('@')
domain = email[pos + 1:]
#print(domain)
newdict[domain] = newdict.get(domain, 0) + 1
print(newdict)