https://py.checkio.org/mission/house-password/ Voir le lien pour plus de détails (découpé).
[Python> Implémentation> Contient-il des nombres | Contient-il l'alphabet (majuscules et minuscules)> Utilisez sum (), map (), str.isalpha](http://qiita.com/7of9/items/ b5a307fed35f333f1d29) J'ai utilisé la méthode enseignée par @SaitoTsutomu.
v0.1
Non conforme à 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
Adopté toutes les affirmations.
v0.2
Support d'avertissement pour PEP8
Utilisez http://pep8online.com.
L'avertissement suivant demeure.
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