304 North Cardinal St.
Dorchester Center, MA 02124

Group() Groups() Groupdict() Hacker Rank Solution – Queslers

Problem : Group() Groups() Groupdict() Hacker Rank Solution

A group() expression returns one or more subgroups of the match.
Code :

``````>>> import re
>>> m.group(0)       # The entire match
>>> m.group(1)       # The first parenthesized subgroup.
>>> m.group(2)       # The second parenthesized subgroup.
'hackerrank'
>>> m.group(3)       # The third parenthesized subgroup.
'com'
>>> m.group(1,2,3)   # Multiple arguments give us a tuple.
``````

groups()
A groups() expression returns a tuple containing all the subgroups of the match.
Code :

``````>>> import re
>>> m.groups()
``````

groupdict()
A groupdict() expression returns a dictionary containing all the named subgroups of the match, keyed by the subgroup name.
Code :

``````>>> m = re.match(r'(?P<user>\w+)@(?P<website>\w+)\.(?P<extension>\w+)','myname@hackerrank.com')
>>> m.groupdict()
{'website': 'hackerrank', 'user': 'myname', 'extension': 'com'}
``````

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.

Input Format :

A single line of input containing the string S.

Constraints :

• 0 < len(S) < 100

Output Format :

Print the first occurrence of the repeating character. If there are no repeating characters, print -1.

Sample Input :

``````..12345678910111213141516171820212223
``````

Sample Output :

``````1
``````

Explanation :

.. is the first repeating character, but it is not alphanumeric.
1 is the first (from left to right) alphanumeric repeating character of the string in the substring 111.

Group() Groups() Groupdict() Hacker Rank Solution in python 2

``````from __future__ import print_function
import re
r=re.search(r'([0-9a-zA-Z])\1',raw_input())
print(r.group(1) if r else -1)``````

Group() Groups() Groupdict() Hacker Rank Solution in python 3

``````# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
m = re.findall(r"([A-Za-z0-9])\1+",input())
if m:
print(m[0])
else:
print(-1)``````

Group() Groups() Groupdict() Hacker Rank Solution in pypy

``````# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
s=raw_input()
m=re.search(r'([a-z0-9])\1+',s)
if m is None:
print -1
else:
print m.group(0)[1]``````

Group() Groups() Groupdict() Hacker Rank Solution in pypy 3

``````# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
m = re.search(r'([a-zA-Z0-9])\1', input().strip())
print(m.group(1) if m else -1)
``````
Group() Groups() Groupdict() Hacker Rank Solution Review:

In our experience, we suggest you solve this Group() Groups() Groupdict() Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Group() Groups() Groupdict() is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution

Group() Groups() Groupdict() Hacker Rank Solution Conclusion:

I hope this Group() Groups() Groupdict() Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

Mini-Max Sum Hacker Rank Solution

String Validators Hacker Rank Solution

Text Alignment Hacker Rank solution

String validators Hacker Rank Solution