最後のif x
の最後のif xは、前後に数字以外のものがあった場合にも必要ですよね。
>python Python 2.4.4 (#2, Apr 15 2008, 23:43:20) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> SEP = re.compile(r'[^\d]+') >>> def embedded_numbers(s): ... return [int(x) for x in SEP.split(s) if x] ... >>> embedded_numbers('hoge1234') [1234] >>> [x for x in SEP.split('hoge1234')] ['', '1234']
バージョンは・・・lennyになれば2.5!