I have a headache and dictionary like this:
{a: ['+','+','-','-','+','-','-','+'],
b: ['+','+','+','-','-','+','+','+','-'],
c: ['-','-','-','+','+','+']}
And I want to know how many times the string of values change, something like this:
a = 4
b = 3
c = 1
I have tried using groupby from itertools, by doing this:
for k, v in mydict.iteritems():
print k + ' ' + str([len(list(g[1])) for g in groupby(list(v)) if g[0] =='+'])
But I get only a list containing two values (two string switches).. I have tried changing the '+' and '-' characters without success, any recommendations?