2b. (8 pts) Recall that the sub (substitute) function in the re module is defined like...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2b. (8 pts) Recall that the sub (substitute) function in the re module is defined like def sub (re_pattern str, rep_func callable, text : str) -> str: It searches text for substrings matching re_pattern; for every substring that it finds, it replaces it with the result of calling rep_func, supplying the resulting match object as its argument. For example re.sub (r"a\d", (lambda m "A"), "a5bcayza7") returns "AbcayzA": every occurrence of a followed by any digit is replaced by "A". We don't use or $ in this pattern, because the pattern can match anywhere in text. Here rep_func is a simple lambda that does not use the match object it is passed, but m is bound to the match object so the match object could have been used inside the lambda. We define a cluster of values as one or more possibly signed one-digit integers (including 0) that appear between < and >; two or more cluster values are separated by commas (,) and there are no spaces inside the cluster. For example <2> is a cluster; so is . Note that the characters and > have no special meaning in RE. Define a pattern and rep_func below, so the call re. sub (pattern, rep_func, text) replaces every cluster in text by the sum of its values. For example re.sub (pattern, rep_func, 'I met <1,2> and <1,5, -3,1>) returns the string 'I met 3 and 4' pattern = def rep func (mo) -> str : #mo is the match object for each time pattern matches in text 2c. (1 pt) What result string is returned by the call re.sub (pattern, rep_func, 'answer = <1, <3,4>,2>). 2b. (8 pts) Recall that the sub (substitute) function in the re module is defined like def sub (re_pattern str, rep_func callable, text : str) -> str: It searches text for substrings matching re_pattern; for every substring that it finds, it replaces it with the result of calling rep_func, supplying the resulting match object as its argument. For example re.sub (r"a\d", (lambda m "A"), "a5bcayza7") returns "AbcayzA": every occurrence of a followed by any digit is replaced by "A". We don't use or $ in this pattern, because the pattern can match anywhere in text. Here rep_func is a simple lambda that does not use the match object it is passed, but m is bound to the match object so the match object could have been used inside the lambda. We define a cluster of values as one or more possibly signed one-digit integers (including 0) that appear between < and >; two or more cluster values are separated by commas (,) and there are no spaces inside the cluster. For example <2> is a cluster; so is . Note that the characters and > have no special meaning in RE. Define a pattern and rep_func below, so the call re. sub (pattern, rep_func, text) replaces every cluster in text by the sum of its values. For example re.sub (pattern, rep_func, 'I met <1,2> and <1,5, -3,1>) returns the string 'I met 3 and 4' pattern = def rep func (mo) -> str : #mo is the match object for each time pattern matches in text 2c. (1 pt) What result string is returned by the call re.sub (pattern, rep_func, 'answer = <1, <3,4>,2>).
Expert Answer:
Related Book For
Statistics For Business And Economics
ISBN: 9780321826237
12th Edition
Authors: James T. McClave, P. George Benson, Terry T Sincich
Posted Date:
Students also viewed these programming questions
-
5) On the graphs below show the difference between a change in price and a change in demand. Fully label graphs for full marks! (2+2 marks) Change in price Change in demand X 6) A change in the price...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
There are three mutually exclusive projects, where the basic information is provided below. Assume a DN alternative does not exist. Initial Cost Annual net profit Useful Life Salvage value A $25,000...
-
Locate the Home Depot, Inc., 2012 financial statements. Briefly peruse the financial statements and answer the following questions: a. Name the titles of each of Home Depot's financial statements...
-
Assume that Sarazan Company has a share-option plan for top management. Each share option represents the right to purchase a $1 par value ordinary share in the future at a price equal to the fair...
-
Consider the problem of a semi-infinite fluid subject to a constant shear at the interface. This can be caused, for instance, by a surface-tension gradient. Show that the following differential...
-
The Cubbie Inn is a restaurant in DeKalb, Illinois. It specializes in deluxe sandwiches in a moderate price range. Bill Michael, the manager of Cubbie Inn, has determined that during the last 2 years...
-
Ames Trading Company has the following products in its ending inventory. Cost per Market per Product Quantity Mountain bikes Skateboards Gliders 14 12 30 Unit $ 710 240 910 Unit $ 640 280 870 Compute...
-
how to Link it to my GitHub repository.? Create a new directory under csd-310 and name it module_9. Create a new file under the module_9 directory and name it pysports_join_queries.py. Add the...
-
Compute the horizontal force P required to prevent the 900 lb block, shown below from sliding down the plane. The coefficient of friction between the block and the plane is 0.20. W = 900 lb 35 ASSI 35
-
Network One is expected to pay a dividend of $3.70 at the end of the year. If the company has a required rate of return of 11%, and constant growth rate of 4%, what is the current stock price? Your...
-
Beishan Technologies' end-of-year free cash flow (FCF) is expected to be $70 million, and free cash flow is expected to grow at a constant rate of 5% a year in the future. The firm's WACC is 10%, and...
-
-$10 million, Petty Corporation forecasts a negative free cash flow for the coming year, with FCF=- but it expects positive numbers thereafter, with FCF2= $17 million. After Year 2, FCF is expected...
-
Based on the corporate valuation model, SG Telecom's total corporate value is $750 million. Its balance sheet shows $100 million notes payable, $200 million of long-term debt, $40 million of common...
-
How many home runs would Homer need to hit next season to have a 12-year mean of 60?
-
On October 1, 2021, Adoll Company acquired 2,600 shares of its $1 par value stock for $38 per share and held these shares in treasury. On March 1, 2023, Adoll resold all the treasury shares for $34...
-
Identify the problem(s) in each of the residual plots shown below. d. 2
-
Each week coaches in the National Football League (NFL) face a decision during the game. On fourth-down, should the team punt the ball or go for a first-down? To aid in the decision-making process,...
-
What is statistics?
-
You have been asked to consult for an entrepreneur who is assembling investors for a new professional sport league. A critical decision for the league will be whether to organize under a...
-
Does a company share its risk by issuing equity or debt?
-
How are the features of a convertible bond similar to both debt and equity?
Study smarter with the SolutionInn App