+ 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
14 Answers
+ 5
YuGiMob , where did you see this expression? 😉
You forgot to put r in front of the expression. ☺️
+ 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
+ 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)
+ 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')
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")
0
This expression can be shortened. 😎
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 ;)
0
I have reduced your code to 75 characters. 😎
0
Solo I got it to 76, I wonder how did you squeeze that last char out
EDIT: Nevermind, got it to 74 😅
0
I have reduced code to 71 characters. 😎
0
haha, almost, just without the variable, and yours only shows sequential repetition.☺️
- 1
76 is also good. ☺️
Let this be your next task 😎
- 1
Ok now I am genuinely interested... how
- 1
How can i learn ❤️