Skip to content

Instantly share code, notes, and snippets.

@r-wheeler
Created October 30, 2015 16:27
Show Gist options
  • Save r-wheeler/6a24715340a3710ee640 to your computer and use it in GitHub Desktop.
Save r-wheeler/6a24715340a3710ee640 to your computer and use it in GitHub Desktop.
hackerrank alternating 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