0
How can i add the "upper-clause" in this function? Because I need to exclude up/low case mismatches.
lambda s='Sstring99': min([len(x) for x in [set(x) for x in [s[x:x+2] for x in range(len(s)-1)]]])==1 and s.isalpha() """ i tried in this way but it doesn't work: s='Sstring99' and s.upper(): min([len(x) for x in [set(x) for x in [s[x:x+2] for x in range(len(s)-1)]]])==1 and s.isalpha() or s='Sstring99': min([len(x) for x in [set(x) for x in [s[x:x+2] for x in range(len(s)-1)]]])==1 and s.isalpha() and s.upper() etc. """
9 odpowiedzi
+ 4
Andrex try this :
lambda s: min([len(x) for x in [set(x.lower()) for x in [s[x:x+2] for x in range(len(s)-1)]]])==1 and s.isalpha()
I just converted the set elements to lower case.
+ 6
May be it would be better to explain what are going to achieve with your code, rather then picking and showing some code fragments. Somtimes a better readable code results when you are going to do this.
+ 3
So the duplicated letters has to be consecutive like "better" (2x t), or can also be like this "sometimes" (2x m)?
+ 2
when a lambda statement becomes so complicated, it's better to use a normal function to perform the task.
+ 2
It is required to be consecutive
+ 1
It's just a task for training the usage of lambda functions, it's not a part of something bigger
0
John Robotane, I need to solve this task use the lambda function)
Lothar, Sure, here is a task description.
Find double letter. My code solves not always points, result is:
hello => True | Passed.
world => False | Passed.
Happen => True | Passed.
Gg => False | Not passed. Expected True
Hi!! => False | Passed.
88f => False | Passed.
0
Andrex I want to know something, the string you used in your post should it return True or should it return False? since it has two 's' and two digits.
0
Gh