Skip to content

Instantly share code, notes, and snippets.

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#myPage">Mani Chabba</a>
</div>
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
hour = list()
count = dict()
for line in handle:
if not line.startswith("From ") : continue
time = line.split()[5]
hour.append(time.split(":")[0])
for key in hour:
fname = input("Enter file name:")
handler = open(fname,'r')
file = handler.read()
words = file.split()
req = input("Enter the word you want to find in the file:")
ans = words.count(req)
print (req," occurs ",ans, " times.")
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
emails = list()
count = dict()
for line in handle:
if not line.startswith("From ") : continue
words = line.split()
emails.append (words[1])
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
for word in line.split():
if word not in lst:
lst.append(word)
lst.sort()
print lst
@manichabba
manichabba / spam.py
Created July 23, 2016 21:29
Python exercise 7.2
spam = 0.0
Count = 0
fname = raw_input("Enter file name: ")
try:
fh = open(fname)
except:
print "File cannot be opened:",fname
exit ()
for line in fh: