Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!