This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fname = input("Enter file name: ") | |
if len(fname) < 1 : fname = "mbox-short.txt" | |
fh = open(fname) | |
count = 0 | |
for line in fh: | |
x=line.rstrip().split() | |
if 'From' in x: | |
print(x[1]) | |
count+=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
hand = open("regex_sum_24962.txt") | |
x=list() | |
for line in hand: | |
y = re.findall('[0-9]+',line) | |
x = x+y | |
sum=0 | |
for z in x: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = raw_input("Enter file:") | |
if len(name) < 1 : name = "mbox-short.txt" | |
handle = open(name) | |
d=dict() | |
for line in handle: | |
if not line.startswith("From "): | |
continue | |
else: | |
line=line.split() | |
line=line[5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fname = raw_input("Enter file name: ") | |
fh = open(fname) | |
lst = list() # list for the desired output | |
for line in fh: # to read every line of file romeo.txt | |
word= line.rstrip().split() # to eliminate the unwanted blanks and turn the line into a list of words | |
for element in word: # check every element in word | |
if element in lst: # if element is repeated | |
continue # do nothing | |
else : # else if element is not in the list | |
lst.append(element) # append |