+9

# Problem with regex Python

This try is not bad, but I want (1,1),(2,2),(1,1) What can I do? https://code.sololearn.com/cULWiH3ynUei/?ref=app

7/2/2022 6:14:20 AM

Oma Falk

+7

What would be the output for 11112211? * 11 11 22 11 or * 1111 22 11? https://code.sololearn.com/c50c28417yUJ/?ref=app

+10

Oma Falk , if you don't have to stick on regex, itertools groupby may help: https://code.sololearn.com/chxhI5t5LmM1/?ref=app

+7

This is my take: (sorry if its late a bit.) ❤ https://code.sololearn.com/cNqnHTuXeh7L/?ref=app

+3

Lisa 1111 22 11

+3

Oma Falk I added a regex with list comprehension found on geeksforgeeks

+3

Curiosity: what is this 1 iteration loop for? for i in range(1):

+2

import regex as re expr = r"(\d)\1+" expr2 = r"(\d)(\1{1})"#this works expr3 = r"(\d)(\1+)"#also works,but differently def step(word, ex): wc= re.findall(ex,word) return wc l="311225555511" print(step(l,expr)) print(step(l,expr2)) print(step(l,expr3))

+2

or maybe this? https://code.sololearn.com/cxEn0ld063TY/?ref=app

+2

Bob_Li fantastic!

+1