Why doesnt my REGEX work? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 6

Why doesnt my REGEX work?

I am challenging myself to solve Code Coach challenges with Regex expressions but I do not understand why this one isnt working as intended: it should output Unique if the entered input has no repeated charactes and Deja Vu if at least a letter repeats https://code.sololearn.com/cMLazS1Qehyg/?ref=app

28th Jul 2022, 2:10 PM
YuGiMob
YuGiMob - avatar
14 Respostas
+ 5
YuGiMob , where did you see this expression? ūüėČ You forgot to put r in front of the expression. ‚ėļÔłŹ
28th Jul 2022, 2:37 PM
Solo
Solo - avatar
+ 1
As stated in my question: "I am challenging myself to solve Code Coach challenges with Regex" I know it is possible to do it in a similar fashion as you posted, but sadly this is not helping me understand why my regex is wrong
28th Jul 2022, 2:36 PM
YuGiMob
YuGiMob - avatar
+ 1
Solo as soon as you said it, I think I know how you did it. it looks like this atm: import re b="Deja Vu"if re.match(r".*(.)\1",input())else"Unique" print(b)
28th Jul 2022, 9:06 PM
YuGiMob
YuGiMob - avatar
+ 1
Slick I used a list and a set... keyed_characters = list(input()) dedup_input = set(keyed_characters) if len(keyed_characters) > len(dedup_input): print('Deja Vu') else: print('Unique')
29th Jul 2022, 2:25 AM
Paul K Sadler
Paul K Sadler - avatar
0
It fails because your regex is wrong. It doesn't require regex. string = input() lett_count = {lett: string.count(lett) for lett in list(string)} dups = 0 for value in lett_count.values(): if value > 1: print("deja vu") dupes = True break if not dupes: print("unique")
28th Jul 2022, 2:30 PM
Slick
Slick - avatar
0
This expression can be shortened. ūüėé
28th Jul 2022, 2:45 PM
Solo
Solo - avatar
0
I found online certain approaches to tackle it, was pretty much going over it until it did work on regex101 but it didnt work here. I am at the moment shortening it ;)
28th Jul 2022, 2:47 PM
YuGiMob
YuGiMob - avatar
0
I have reduced your code to 75 characters. ūüėé
28th Jul 2022, 3:03 PM
Solo
Solo - avatar
0
Solo I got it to 76, I wonder how did you squeeze that last char out EDIT: Nevermind, got it to 74 ūüėÖ
28th Jul 2022, 3:34 PM
YuGiMob
YuGiMob - avatar
0
I have reduced code to 71 characters. ūüėé
28th Jul 2022, 9:00 PM
Solo
Solo - avatar
0
haha, almost, just without the variable, and yours only shows sequential repetition.‚ėļÔłŹ
28th Jul 2022, 9:16 PM
Solo
Solo - avatar
- 1
76 is also good. ‚ėļÔłŹ Let this be your next task ūüėé
28th Jul 2022, 3:40 PM
Solo
Solo - avatar
- 1
Ok now I am genuinely interested... how
28th Jul 2022, 9:03 PM
YuGiMob
YuGiMob - avatar
- 1
How can i learn ‚̧ԳŹ
29th Jul 2022, 2:20 PM
Malik Rashid