Skip to content
Advertisement

Labeling sentences from different nested dictionaries

I created a function to extract sentences from a specific key in a nested file. Now I would like to include in this function a label each time it comes to a new dictionary.

Each time the the value HEADER appears marks the begining of a NEW story. So I would like to label the sentences that belong to the same story. And differentiate those that are different.

The data looks like the following:

JavaScript

The function

JavaScript

enter image description here

The result that I would like to obtain (with the labels in a new column) enter image description here

Advertisement

Answer

You can iterate over the records and increment the label every time the c value is HEADER.

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement