-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc3w2.py
More file actions
182 lines (128 loc) · 3.23 KB
/
c3w2.py
File metadata and controls
182 lines (128 loc) · 3.23 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
# if line.find('From:') >= 0:
# print(line)
# RE IS REGULAR EXPRESSION LIBRARY
# import re
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
# if re.search('From:', line) :
# print(line)
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
# if line.startswith('From:') >= 0:
# print(line)
# RE IS REGULAR EXPRESSION LIBRARY
# import re
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
# if re.search('^From:', line) :
# print(line)
# import re
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
# if re.search('^X.*:', line) :
# print(line)
# import re
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
# if re.search('^X-\S+:', line) :
# print(line)
# import re
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
# line= re.findall('[0-9]+',line) #finds all the nos in text
# print(line)
# import re
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
# line= re.findall('[AEIOU]+',line) #finds all the uppercase vowels in text
# print(line)
#GREEDY MATCHING
# import re
# x = 'From: Using the : character'
# y = re.findall('^F.+:',x)
# print(y)
#NON-GREEDY MATCHING
# import re
# x = 'From: Using the : character'
# y = re.findall('^F.+?:',x)
# print(y)
# import re
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
#
# line = re.findall('\S+@\S+',line)
# print(line)
# import re
# hand = open('text.txt')
# for line in hand:
# line = line.rstrip()
#
# line = re.findall('^From (\S+@\S+)',line)
# print(line)
# data = "From stephen.marquard@uct.ac.za Sat Jan 5 09:312:83 2008"
# atpos = data.find('@')
# print(atpos)
# sppos = data.find(' ',atpos)
# print(sppos)
# host = data[atpos+1 : sppos]
# print(host)
# import re
# data = "From stephen.marquard@uct.ac.za Sat Jan 5 09:312:83 2008"
# y = re.findall('@([^ ]*)',data) #those square brackets indicate non-blank char and ^ in brackets means everything but space
# print(y)
# import re
# data = "From stephen.marquard@uct.ac.za Sat Jan 5 09:312:83 2008"
# y = re.findall('^From .*@([^ ]*)',data)
# print(y)
#
#
# import re
# hand = open('text.txt')
# numlist = list()
# for line in hand:
# line = line.rstrip()
# stuff = re.findall('^X-DSPAM-Confidence: ([0-9.]+)',line)
# if len(stuff) != 1 : continue
# num = float(stuff[0])
# numlist.append(num)
# print('Maximum:',max(numlist))
# import re
# x = 'WE just received $10.00 for cookies'
# y = re.findall('\$[0-9.]+',x)
# print(y)
# CODE BELOW NOT WORKING
# import re
# hand = open('text1.txt')
# numlist = list()
# for line in hand:
# line = line.rstrip()
# stuff = re.findall('[0-9]+',line)
# if len(stuff) != 1 : continue
# numlist = numlist.append(int(stuff))
# print(sum(numlist))
# import re
#
# hand = open("text1.txt")
# x=list()
# for line in hand:
# y = re.findall('[0-9]+',line)
# x = x+y
#
# sum=0
# for z in x:
# sum = sum + int(z)
#
# print(sum)
import re
print(sum([int(i) for i in re.findall('[0-9]+',open("text1.txt").read())]))