Created
October 30, 2015 16:27
-
-
Save r-wheeler/6a24715340a3710ee640 to your computer and use it in GitHub Desktop.
hackerrank alternating characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
import operator | |
def algo(string): | |
s = list(string) | |
g = sum(len(list(v)) -1 for (k,v) in groupby(s, key=operator.itemgetter(0))) | |
return g | |
num = raw_input() | |
cases = [] | |
for case in range(int(num)): | |
cases.append(raw_input()) | |
for c in cases: | |
print algo(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment