check.io 上的題目:合格的密碼須含數字
此系列文章主要是自己在解題時覺得有趣的題目,記錄下來讓自己以後方便複習,有興趣的人可以參考看看
先來看看題目
解題步驟
- 密碼須大於6位數
- 至少需包含一個數字
map 用法
語法: map(function: iterable)
1 | def square(x): |
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