In this HackerRank Group(), Groups() & Groupdict() problem solution You are given a string S. Your task is to find the first occurrence of an alphanumeric character in S (read from left to right) that has consecutive repetitions.

HackerRank Group(), Groups() & Groupdict() in python problem solution

HackerRank Group(), Groups() & Groupdict() in python problem solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
S = raw_input()
repeat = re.search(r'([A-Za-z0-9])\1', S)

if repeat is None:
    print -1
else:
    print repeat.group(1)[0]