V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
thedevil7
V2EX  ›  Python

求教, 如何从一段输入中取出其中的数字?

  •  
  •   thedevil7 ·
    thedevil7 · 2012-04-25 22:20:09 +08:00 · 2628 次点击
    这是一个创建于 4390 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如, 输入" 1, 2, 3 ,4, 11, 14, 16,av20,bc30" 所有的符号不要, 所有字母不要, 最后只要一个 list = [1, 2, 3, 4, 11, 14, 16, 20, 30].
    我现在可以做到用正则表达式剔除除了数字的部分, 得到一个字符串"1 2 3 4 11 14 16 20 30".
    p = re.compile(r'\D+')
    p.sub(" ", rawdata)
    但是不知道下一步怎么办了.
    1 条回复    1970-01-01 08:00:00 +08:00
    thedevil7
        1
    thedevil7  
    OP
       2012-04-25 22:24:26 +08:00
    利用 [ int(i) for i in re.split(p, rawdata) ] 解决了.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2166 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 05:25 · PVG 13:25 · LAX 22:25 · JFK 01:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.