https://py.checkio.org/mission/house-password/ Siehe den Link für Details (ausgeschnitten).
[Python> Implementierung> Enthält es Zahlen | Enthält es Alphabet (Groß- und Kleinbuchstaben)> Verwenden Sie sum (), map (), str.isalpha](http://qiita.com/7of9/items/ b5a307fed35f333f1d29) Ich habe die von @SaitoTsutomu gelehrte Methode verwendet.
v0.1
Nicht kompatibel mit PEP8.
numlower = lambda s:sum(map(str.islower, s))
numupper = lambda s:sum(map(str.isupper, s))
numdigit = lambda s:sum(map(str.isdigit, s))
def checkLowerUpperDigit(data):
return (numlower(data) >0 and
numupper(data) >0 and
numdigit(data) >0)
def checkio(data):
print(data)
if len(data) < 10:
return False
if checkLowerUpperDigit(data) == False:
return False
return True
#Some hints
#Just check all conditions
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio('A1213pokl') == False, "1st example"
assert checkio('bAse730onE4') == True, "2nd example"
assert checkio('asasasasasasasaas') == False, "3rd example"
assert checkio('QWERTYqwerty') == False, "4th example"
assert checkio('123456123456') == False, "5th example"
assert checkio('QwErTy911poqqqq') == True, "6th example"
run
A1213pokl
bAse730onE4
asasasasasasasaas
QWERTYqwerty
123456123456
QwErTy911poqqqq
Alle Behauptungen bestanden.
v0.2
Warnunterstützung für PEP8
Verwenden Sie http://pep8online.com.
Die folgende Warnung bleibt bestehen.
Line1, Column 1: do not assign a lambda expression, use a def Line2, Column 1: do not assign a lambda expression, use a def Line3, Column 1: do not assign a lambda expression, use a def
numlower = lambda s: sum(map(str.islower, s))
numupper = lambda s: sum(map(str.isupper, s))
numdigit = lambda s: sum(map(str.isdigit, s))
def checkLowerUpperDigit(data):
return (numlower(data) > 0 and
numupper(data) > 0 and
numdigit(data) > 0)
def checkio(data):
print(data)
if len(data) < 10:
return False
if checkLowerUpperDigit(data) is False:
return False
return True
# Some hints
# Just check all conditions
if __name__ == '__main__':
# These "asserts" using only for self-checking and
# not necessary for auto-testing
assert checkio('A1213pokl') is False, "1st example"
assert checkio('bAse730onE4') is True, "2nd example"
assert checkio('asasasasasasasaas') is False, "3rd example"
assert checkio('QWERTYqwerty') is False, "4th example"
assert checkio('123456123456') is False, "5th example"
assert checkio('QwErTy911poqqqq') is True, "6th example"
link
https://stackoverflow.com/questions/25010167/e731-do-not-assign-a-lambda-expression-use-a-def
In my opinion this rule better be avoided and broken when it makes sense, use your judgement.
Recommended Posts