In [9]:
(v, k) = (1, 'test1')
print (k, v)
v = v + 1
print (v, k)
test1 1 2 test1
In [59]:
counts = dict()
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
for line in handle :
if line.startswith('From') :
line = line.split()
if len(line) > 2 :
if line[5][0:2] in counts :
counts[line[5][0:2]] = counts[line[5][0:2]] + 1
elif line[5][0:2] not in counts :
counts[line[5][0:2]] = 1
lst = list()
for key, val in list(counts.items()) :
lst.append((key, val))
lst.sort()
for key, val in lst :
print(key, val)
04 3 06 1 07 1 09 2 10 3 11 6 14 1 15 2 16 4 17 2 18 1 19 1
In [64]:
counts = dict()
name = input("Enter file:")
if len(name) < 1:
name = "mbox-short.txt"
handle = open(name)
for line in handle :
if line.startswith('From') :
line = line.split()
if len(line) > 2 :
if line[5][0:2] in counts :
counts[line[5][0:2]] = counts[line[5][0:2]] + 1
elif line[5][0:2] not in counts :
counts[line[5][0:2]] = 1
counts.items()
sort = sorted(counts.items())
for k, v in sort :
print (k, v)
04 3 06 1 07 1 09 2 10 3 11 6 14 1 15 2 16 4 17 2 18 1 19 1
In [72]:
fhand = open('mbox.txt')
counts = dict()
for line in fhand :
words = line.split()
for word in words :
counts[word] = counts.get(word, 0) + 1
lst = list()
for key, val in counts.items() :
newtup = val, key
lst.append(newtup)
lst = sorted(lst, reverse=True)
for val, key in lst[:10] :
print(key, val)
2007 20413 by 16231 Received: 16173 from 14531 with 12754 -0500 11774 Dec 9267 id 9012 Nov 8988 for 7710
In [ ]: