Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

python:

def shakespeare_position(role, section):
    """
    Question 2 - Regex

    You are reading a Shakespeare play with your friends (as one frequently does) and are given a role.
    You want to know what line immediately precedes YOUR first line in a given section so that you are ready to go
    when it is your turn. Return this line as a string, excluding the character's name.

    Lines will always begin with the character's name followed by a ':' and end in a "." or a "?"
    Each line is separated by a single space.

    THIS MUST BE DONE IN ONE LINE.

    ""

    Args:
    role (str)
    section (str)

    Returns:
    str

    section_1 = 'Benvolio: By my head, here come the Capulets. Mercutio: By my heel, I care not. ' +
    'Tybalt: Gentlemen, good den - a word with one of you. Mercutio: And but one word with one of us?'

    >>> shakespeare_position('Tybalt', section_1)
    'By my heel, I care not.'
    >>> shakespeare_position('Mercutio', section_1)
    'By my head, here come the Capulets.'

    """

# section_1 = 'Benvolio: By my head, here come the Capulets. Mercutio: By my heel, I care not. ' + \
    # 'Tybalt: Gentlemen, good den: a word with one of you. Mercutio: And but one word with one of us?'
    # pprint(shakespeare_position('Tybalt', section_1))
    # pprint(shakespeare_position('Mercutio', section_1))

Expert Solution
Check Mark
Step 1

Program to solve above problem using Python.

Let us Assume character name is followed by :

and Each line is end with '.'

Let us consider the section of Shakespeare playlet

Section: 'Benvolio: By my head, here come the Capulets. Mercutio: By my heel, I care not. ' +
'Tybalt: Gentlemen, good den - a word with one of you. Mercutio: And but one word with one of us?'

Roles: are Benvolio, Mercutio, Tybalt

                                   First line by Benvolio : By my head, here come the Capulets. 

                                   Second line by Mercutio: By my heel, I care not.

                                   Third line by Tybalt: Gentlemen, good den - a word with one of you.

                                   Fourth line by Mercutio: And but one word with one of us?

We give Section and Roles are input to the function shakespeare_position()

You want to know what line immediately precedes, so that given role should get ready for his dialogue. 

 

 

 

Still need help?
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

could you do it in one line of code and using regex please

 

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

could you do it in one line of code and using regex please

 

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY