[GO] CheckIO (Python)> House Password> I implemented it> PEP8: do not assign a lambda expression, use a def

https://py.checkio.org/mission/house-password/ See the link for details (cut out).

[Python> Implementation> Does it contain numbers | Does it contain alphabet (upper and lower case)> Use sum (), map (), str.isalpha](http://qiita.com/7of9/items/ I used the method taught by @SaitoTsutomu in b5a307fed35f333f1d29).

v0.1

Not compliant with 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

Passed all assertions.

v0.2

Warning support for PEP8

Use http://pep8online.com.

The following Warning remains.

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

CheckIO (Python)> House Password> I implemented it> PEP8: do not assign a lambda expression, use a def
Use print in a Python2 lambda expression
CheckIO (Python)> Non-unique Elements> I implemented it
A python lambda expression ...
I want to do it with Python lambda Django, but I will stop