Is there an elegant way (most likely using a list comprehension) to concatenate all neighboring string elements in an list?
I have a list where there is no functional difference between multiple strings in a row and all of those strings concatenated into a single string, but both for readability and for equivalence testing, I would like to concatenate these together. There can be other non-string elements in the list that can break up the strings. These need to remain between the concatenated groups of strings.
For example, I could have
rule = ["a", "b", C(), "d", "ef", "g"]
and instead, I want
rule = ["ab", C(), "defg"]