house-password
import re a = re.compile('[a-z]') A = re.compile('[A-Z]') n = re.compile('[0-9]') lsre = (a, A, n) def checkio(data): if len(data) < 10: return False for p in lsre: m = p.search(data) if m is None: return False return True
string.digits というのもあるんですね
正規表現ですべて含むもの とか書けないのでループで対処した
綺麗
import re def checkio(data): 'Return True if password strong and False if not' return bool(len(data) >= 10 \ and filter(lambda a:a.isupper(),data) \ and filter(lambda a:a.islower(),data) \ and filter(lambda a:a.isdigit(),data))
http://www.checkio.org/mission/house-password/publications/oduvan/python-27/first/
ためしたけど lambda のところ全部 True になるしなんだこれって感じしたんだけど Python 2.7 だと False になって愕然としている……
Python 2.7.5 (default, Aug 25 2013, 00:04:04) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> data = 'spam123' >>> bool(filter(lambda s:s.isupper(),data)) False Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> data = 'spam123' >>> bool(filter(lambda s:s.isupper(),data)) True
追記
Qiita で解説してもらえた
http://qiita.com/trsqxyz/items/50e6e59e23995b6c2b41