>>> import re
>>> def f(s):
... return list(map(int, re.split(r'(?<=\d)-', s)))
...
...
>>> f("0-23")
[0, 23]
>>> f("3--7")
[3, -7]
>>> f("-3-7")
[-3, 7]
>>> f("-3--7")
[-3, -7]
Run Code Online (Sandbox Code Playgroud)
-仅当模式前面带有digit(\d)时,模式才会匹配.
list(..)如果使用Python 2.x,则可以省略.
| 归档时间: |
|
| 查看次数: |
250 次 |
| 最近记录: |