0%

[筆記] Check.io - Acceptable Password II

check.io 上的題目:合格的密碼須含數字
此系列文章主要是自己在解題時覺得有趣的題目,記錄下來讓自己以後方便複習,有興趣的人可以參考看看

先來看看題目

解題步驟

  • 密碼須大於6位數
  • 至少需包含一個數字

map 用法

語法: map(function: iterable)

1
2
3
4
def square(x):
return x * x

map(square, [1, 2, 3, 4]) #Output [2, 4, 6, 8]

any 用法

解答:

def is_acceptable_password(password: str) -> bool:
    # your code here
    return True if len(password) > 6 and any(map(str.isdigit, password)) else False