Skip to content

Commit c2bd6b8

Browse files
committed
Started solving chapter 11 problems
1 parent 07b713f commit c2bd6b8

File tree

4 files changed

+30
-61
lines changed

4 files changed

+30
-61
lines changed

Chapter 11/Exercise11_1.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

Chapter 11/Exercise11_2.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

Chapter 11/Exercise11_3.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

Chapter 11/Problem11_15.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import time
2+
import re
3+
4+
def timing(func, n):
5+
'runs func on input returned by buildInput'
6+
funcInput = n # obtain input for func
7+
8+
start = time.time() # take start time
9+
func(funcInput) # run func on funcInput
10+
end = time.time() # take end time
11+
timefinal = float(end) - float(start)
12+
return timefinal # return execution time
13+
14+
def maketransreplace(string):
15+
16+
table = str.maketrans('!,.:;?', 6*' ')
17+
stringue = string.translate(table)
18+
19+
def replacereplace(string):
20+
21+
string = string.replace('!,.:;?', 6*' ')
22+
23+
def regex(string):
24+
25+
prog = re.compile('[a-zA-Z]*')
26+
result = prog.match(string)
27+
28+
print(timing(maketransreplace, 'texto com pontuacao! \n mais pontuacao? \n talvez, mais, pontuacao?'))
29+
print(timing(replacereplace, 'texto com pontuacao! \n mais pontuacao? \n talvez, mais, pontuacao?'))
30+
print(timing(regex, 'texto com pontuacao! \n mais pontuacao? \n talvez, mais, pontuacao?'))

0 commit comments

Comments
 (0)