C5W3A2E4: Trigger word detection not updating previous_segments

Hi everyone,

This is concerning Course 5, Week 3, Assignement 2, Exercise 2 “Trigger Word Detection”.
Why is “previous_segments” not being updated? I understand that the list “previous_segments” is needed to make sure that the segments inserted into “background” do not overlap. If we don’t update the list after every insertion, how can we make sure overlap does not happen?

Thank you and best regards,

The insert_audio_clip() function does update previous_segments.
That’s part of the code you write in Step 3 of that function.

Oh you’re absolutely right. I thought I underrstood about local variables vs. global variables. It seems I don’t.

So the variable “previous_segments” is created as an empty list inside the function create_training_example(). There it is handed over to the insert_audio_clip() function, where it is updated. But what confuses me, is that it’s not handed back to the create_training_example() function. Apperently you don’t need to return input variables to update them in the previous function. Is that correct?

Thank you!

Python has some complicated habits regarding variables and values.

Maybe this is useful:

1 Like

Thank you @TMosh , I had the same question. That link was really helpful. So basically in python using list.append(x) in the function after passing it through the call, it will append the item to the outer_list(By reference).