Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the process _ scenes function to separate lines in scene _ text by , separate speakers from the beginnings of their speeches ( using

Complete the process_scenes function to separate lines in scene_text by
, separate speakers from the beginnings of their speeches (using regex), and collect the multiline speeches in a single string. Each speaker-line pair should be stored in the defaultdict structure set up in the code below. Store each speaker-line pair as a list. Process act_scene_texts with process_scenes, and print the first five lines of ACT I, SCENE 1. Without changing any preset code, and onnly adding between #code starts here and # code ends here.
from collections import defaultdict
def process_scenes(act_scene_texts):
data = defaultdict(lambda : defaultdict(list))
current_act, current_scene ="",""
## set dictionary keys
for act_scene, scene_text in zip(act_scene_texts[1::2], act_scene_texts[2::2]):
if act_scene[:3]== "ACT": # if it's a new act, update the current_act value
#---your code starts here---(separate and collect the act/scene information)
#---your code stops here---
else:# otherwise assign the act_scene_heading
#---your code sarts here---(just update the current_scene)
#---your code stops here---
speaker, speech ="",""
for line in scene_text.split("
"):
#---Your code starts here---
#---Your code stops here---
return data
data = process_scenes(act_scene_texts)
data['ACT I']['SCENE 1'][:5]

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

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions

Question

denigration of emotional outbursts; being reserved;

Answered: 1 week ago