I have a json file with a series of dictionaries within a list, like this:
{"turns": [{
"speaker": "A",
"says": "Hello."
"other": "aaaa"},
{
"speaker": "B",
"says": "Hi."
"other": "bbbb"},
{
"speaker": "B",
"says": "I'm busy now."
"other": "ccccc"},
{
"speaker": "A",
"says": "See you later?"
"other": "dddd"},
{
"speaker": "B",
"says": "Sure."
"other": "eeee"},
{
"speaker": "B",
"says": "Bye"
"other": "ffff"},
{
"speaker": "A",
"says": "Bye bye."
"other": "gggg"}]
I want to combine the keys "says" and "other" keys I might have, when it is the same consecutive "speaker", like so:
{"turns": [{
"speaker": "A",
"says": "Hello."
"other": "aaaaa"},
{
"speaker": "B",
"says": "Hi. I'm busy now."
"other": "bbbb cccc"},
{
"speaker": "A",
"says": "See you later?"
"other": "dddd"},
{
"speaker": "B",
"says": "Sure. Bye"
"other": "eeee ffff"},
{
"speaker": "A",
"says": "Bye bye."
"other": "gggg"}]
I am still new to python and dealing with json files, so I honestly am unsure where to even begin. I assume I could use .join() somehow, but I don't know how to check for the same key-value paring appearing consecutively. Can anyone help?