假设有一个tuple为[['128 MB', '27 PERCENT']]
我想将128和27全部转换成int,该怎么截取字符串?
我想将128和27全部转换成int,该怎么截取字符串?
|
mrluanmaJul 15, 2013
1
>>> [int(x.split(None, 1)[0]) for x in ['128 MB', '27 PERCENT']]
[128, 27] |
|
mrluanmaJul 15, 2013
3
@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. |
|
ToughGuyJul 16, 2013
4
import re
[map(int, re.findall(r'\d+', x)) for x in ['128 MB', '27 PERCENT']] 新手... |