Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Created by Cépagrave [busyCarpenting]
- print((lambda p:4<len(p)<11*(1-p.isalnum())*(len(p.split())<2)*bool({*p}&{*'0123456789'}))(input()))
- """
- Explanation of this code:
- the challenge rules are:
- 1 - min length of 5
- 2 - max length of 10
- 3 - at least 1 digit
- 4 - at least 1 special character
- 5 - no space
- // First, the code global structure is:
- print((lambda p: -- long expression -- )(input()))
- the result here is: input is taken, passed as "p" argument to the lambda, this argument is used in the long expression, which will return a boolean (True or False)
- // Now, the long expression:
- 4<len(p)<11*(1-p.isalnum())*(len(p.split())<2)*bool({*p}&{*'0123456789'})
- the center of it is:
- 4<len(p)<11
- it will return True if rules (1) and (2) are respected
- on the right, 3 elements are multiplying 11:
- 11*(--1--)*(--2--)*bool(--3--)
- if one of the 3 elements is evaluated to False (or 0), then 11*..*..*.. will take the value 0, and len(p)<0 will return "False"
- // So now, the 3 elements:
- (1-p.isalnum()) will give 0 if the password is only made of alphanumeric characters (a,b,c,d,...0,1,2,3,...) => special characters needed, or else 1-p.isalphanum() takes value 0 => 11*0=0, len(p)<0 returns False
- (len(p.split())<2) will give 0 if there is one or more space in the password => 11*0, etc...
- bool({*p}&{*'0123456789'}) this is evaluating a sets intersection:
- {*p} is the set of characters in p
- {*'0123456789'} is the set of string digits
- if they share one element, it will be in the intersection, and bool({"5"}) for ex will evaluate to True, while bool(--empty set--) will evaluate to False, thus 0, => 11*0, etc...
- """
- # old version:
- # print((lambda p:bool(4<len(p)<11 and set(p)&{*'0123456789'}and not(p.isalnum()+len(p.split())>1))*'Ok'or'No')(input()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement