1
mrluanma 2013-07-15 16:13:53 +08:00
>>> [int(x.split(None, 1)[0]) for x in ['128 MB', '27 PERCENT']]
[128, 27] |
3
mrluanma 2013-07-15 17:05:19 +08:00
@ioiioi
>>> help("".split) Help on built-in function split: split(...) S.split([sep [,maxsplit]]) -> list of strings Return a list of the words in the string S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result. |
4
ToughGuy 2013-07-16 08:58:49 +08:00
import re
[map(int, re.findall(r'\d+', x)) for x in ['128 MB', '27 PERCENT']] 新手... |