I have a list of "calls and responses", which are pairs of a message and then either a $0$, for a call, or a $1$, for a response. There is some amount of calls, and some amount, potentially unequal, of responses in answer. An example of such a list might be the following:
{{"Call",0},
{"Call 2",0},
{"Response",1},
{"Call 3",0},
{"Response",1},
{"Response 2",1}}
The text is arbitrary, and won't actually contain "call" or "response". What I am trying to do is group this list into an association of calls to responses, so that the list above would become
{{"Call","Call 2"}->{"Response"},
{"Call 3"}->{"Response","Response 2"}}
I looked at GroupBy
and GatherBy
but they seem to re-order the list, which I don't want to do. The order should stay the same, just with calls and responses sorted together. How can I achieve this elegantly?
Bonus points if the answer can also cut out extraneous responses with no calls at the beginning of the list, and extraneous calls with no response at the end of the list.