Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python We have seen three ways to remove punctuation from a string: using string method replace() and string method translate() in Chapter 4, and

In Python

We have seen three ways to remove punctuation from a string: using string method replace() and string method translate() in Chapter 4, and using regular expressions in chapter 11. Compare the running time of each using the experimental running time analysis framework from Section 10.3.

NOTE: Unlike other problems this quarter, this problem will run automatically when you run the module.

Your output should look like this:

Time analysis on the replace(), translate(), and regular expression methods of

removing punctuation from randomly generated strings using the timing framework from Chapter 10.

Average Run-Time of testRegEx(30) is 3.120041e-06 seconds.

Average Run-Time of testRegEx(280) is 2.340007e-05 seconds.

Average Run-Time of testRegEx(530) is 1.872003e-05 seconds.

Average Run-Time of testTranslate(30) is 1.559997e-06 seconds.

Average Run-Time of testTranslate(280) is 6.240058e-06 seconds.

Average Run-Time of testTranslate(530) is 1.560001e-05 seconds.

Average Run-Time of testReplace(30) is 4.680014e-06 seconds.

Average Run-Time of testReplace(280) is 1.092002e-05 seconds.

Average Run-Time of testReplace(530) is 1.872005e-05 seconds.

timeit.Timer() was used for greater accuracy.

the translate function was the most efficient based on time run analysis.

Time analysis on the replace(), translate(), and regular expression methods of

removing punctuation from randomly generated strings using timeit.Timer()

The average time from on 1,000,000 runs for each input, and each function, is reported.

Testing s = oK~

regEx : 1.8607765000002273e-06

translate : 1.1506263000001126e-06

replace : 4.4082109999997955e-06

Testing s = 6k$VbF.D*vn$Rc00SXFnt#j9|#I"&PGu,?J+VWh)=67K]X~[-h|8;$}6kTeL5mwiH&)!su}JAHCLP0^Z"qhneTZXVR7A{ELD`jr]:;3!f(]vha\C9f&_{&j,5%H32Dzr%nZS1um.P-hR0.z!?TEb8.%#Z?km8f1lGX6[|2eL[2NbCUHl*n1EC~^.Js6s#V-d&mjz$:Wt~{^(J=/4ki4|%uQuaLd!uYe

regEx : 1.4057603399999863e-05

translate : 4.357549200000221e-06

replace : 9.560869499999924e-06

Testing s = _]bh}`=__@{v6lYR/Ea2!oQ(!\_A6pfE3v39jJh\Au;FMp%%#U|fA\>li%~rOTf3|CDP~cH!$P;2HctA%b{S,,E7/V#uPebbEXu{Vj-lFS]d"="IuC}dRpd/~Gjn&$!YLiBw//ofjsivWLHG),"dTNGo8-cp$j.1|u*.GKiIp6C4Ad3:(@1jt>ii\TM5u\,Z0qX$g$PH[Q9JM-c5>!4&Y{9UV7v0x:TF>W-2i.`a"h?DGCn&12G4%&jLp^Mn5`],iFnk+!DYops"D

A regEx : 2.5167951100000252e-05

translate : 5.032689299999759e-06

replace : 1.505977929999993e-05

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions