+ 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

2nd Jul 2022, 6:14 AM
Oma Falk
Oma Falk - avatar
11 Answers
+ 7
What would be the output for 11112211? * 11 11 22 11 or * 1111 22 11? https://code.sololearn.com/c50c28417yUJ/?ref=app
2nd Jul 2022, 6:32 AM
Lisa
Lisa - avatar
+ 10
Oma Falk , if you don't have to stick on regex, itertools groupby may help: https://code.sololearn.com/chxhI5t5LmM1/?ref=app
2nd Jul 2022, 7:33 AM
Lothar
Lothar - avatar
+ 7
This is my take: (sorry if its late a bit.) ❀ https://code.sololearn.com/cNqnHTuXeh7L/?ref=app
3rd Jul 2022, 6:08 AM
Siavash Kardar Tehran
Siavash Kardar Tehran - avatar
+ 3
Lisa 1111 22 11
2nd Jul 2022, 6:42 AM
Oma Falk
Oma Falk - avatar
+ 3
Oma Falk I added a regex with list comprehension found on geeksforgeeks
2nd Jul 2022, 7:34 AM
Lisa
Lisa - avatar
+ 3
Curiosity: what is this 1 iteration loop for? for i in range(1):
2nd Jul 2022, 9:35 PM
Emerson Prado
Emerson Prado - avatar
+ 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))
3rd Jul 2022, 4:56 AM
Bob_Li
Bob_Li - avatar
3rd Jul 2022, 5:41 AM
Bob_Li
Bob_Li - avatar
+ 2
Bob_Li fantastic!
3rd Jul 2022, 6:43 AM
Oma Falk
Oma Falk - avatar
+ 1
Emerson Prado some artefacts
3rd Jul 2022, 6:44 AM
Oma Falk
Oma Falk - avatar
+ 1
Oma Falk My question is what is the difference between r"(\d)(\1+)" and r"(\d)\1+"
3rd Jul 2022, 6:47 AM
Bob_Li
Bob_Li - avatar