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. """

30th Mar 2020, 2:10 PM
Andrey Shintar
Andrey Shintar - avatar
9 Réponses
+ 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.
30th Mar 2020, 8:12 PM
John Robotane
John Robotane - avatar
+ 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.
30th Mar 2020, 4:25 PM
Lothar
Lothar - avatar
+ 3
So the duplicated letters has to be consecutive like "better" (2x t), or can also be like this "sometimes" (2x m)?
30th Mar 2020, 7:31 PM
Lothar
Lothar - avatar
+ 2
when a lambda statement becomes so complicated, it's better to use a normal function to perform the task.
30th Mar 2020, 3:20 PM
John Robotane
John Robotane - avatar
+ 2
It is required to be consecutive
30th Mar 2020, 7:38 PM
Andrey Shintar
Andrey Shintar - avatar
+ 1
It's just a task for training the usage of lambda functions, it's not a part of something bigger
30th Mar 2020, 7:12 PM
Andrey Shintar
Andrey Shintar - avatar
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.
30th Mar 2020, 7:03 PM
Andrey Shintar
Andrey Shintar - avatar
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.
30th Mar 2020, 8:59 PM
John Robotane
John Robotane - avatar
0
Gh
31st Mar 2020, 6:56 PM
Chardanay Russell