insert_substrings_into_string(s, substrs): This function takes a string s and a string substrs. The substrs string will contain 0 or more comma-separated substrings. The string s will contain text with 0 or more special placeholder character sequences. These placeholder character sequences will always begin with the percent character %, followed by one or more digits (which form a non- negative number). The function will create a new string from the original string s where all the placeholder character sequences in s are replaced by the substrings in the string substrs. The placeholder %0 should be replaced by the first substring in substrs (i.e., everything before the first comma, if such a comma exists). The placeholder %1 should be replaced by the second substring in substrs (i.e., everything between the first and second comma, if such a comma exists), and so on. The new string should then be returned. Note: If a placeholder s

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

insert_substrings_into_string(s, substrs): This function takes a string s and a string substrs. The substrs string will contain 0 or more comma-separated substrings. The string s will contain text with 0 or more special placeholder character sequences. These placeholder character sequences will always begin with the percent character %, followed by one or more digits (which form a non- negative number). The function will create a new string from the original string s where all the placeholder character sequences in s are replaced by the substrings in the string substrs. The placeholder %0 should be replaced by the first substring in substrs (i.e., everything before the first comma, if such a comma exists). The placeholder %1 should be replaced by the second substring in substrs (i.e., everything between the first and second comma, if such a comma exists), and so on. The new string should then be returned.

Note: If a placeholder sequence refers to an invalid index (e.g., %10 when there are only five sub- strings in substrs), then include the sequence (e.g., %10) as is in the new string.

Note: The order of the placeholder sequences in s may not always be increasing. For instance, %2 may appear before %1. Also, the same placeholder sequence could be repeated (e.g., %2 could appear at one point in s and again at a later point). Each instance of the same sequence would thus be replaced by the same value.

Note: If a space follows a comma in the string substrs, do not include the space as part of the substring to be included in the returned string.

e.g. of how function should work

>>> insert_substrings_into_string("My favorite %0 is %1!!!", "programming language, Python")
'My favorite programming language is Python!!!'

 

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY