Split when character changes in Python
parsing, python, string
Solution
Use `itertools.groupby`:
>>> c = "6#666#665533999"
>>> ["".join(g) for k, g in groupby(c) if k != '#']
['6', '666', '66', '55', '33', '999']
Then have a dictionary which maps each of these sets to a character in the dial pad.
cmap = {'77': 'Q', '9999': 'Z'} # And so forth..
Problem
So I have this string. ``` 6#666#665533999 ``` And I want to parse it into multiple small strings(or until the character changes) and ignoring the `#` so that I can substitute `6 = M or 666 = O or 9 = W` just like a phone's dial pad. ``` 6#666#665533999 -> 6, 666, 66, 55, 33, 999 ``` So I used the `split('#')` method to remove the `#` and can't figure out what to do next.I have tried brute force methods which solves it to a certain extent but is there an easier or more elegant solution to this?