推荐学习书目
› 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
hitluobin
V2EX  ›  Python

python 大神,下面代码看不懂,求大神指导

  •  
  •   hitluobin · Feb 2, 2015 · 4797 views
    This topic created in 4296 days ago, the information mentioned may be changed or developed.

    import itertools

    原tweet = "I luv my <3 iphone & youre awsm apple. DisplayIsAwesome, sooo happppppy :) http://www.apple.com"
    经过tweet = ''.join(''.join(s)[:2] for _, s in itertools.groupby(tweet))
    结果tweet = "I luv my <3 iphone & youre awsm apple. DisplayIsAwesome, soo happy :) http://ww.apple.com"

    求指教实现过程是怎么样的?

    5 replies  •  2015-02-03 10:29:14 +08:00
    Shared
    Shared
    Feb 2, 2015❤️1
    1
    查 itertools 的 groupby 用法
    letv
    letv
    Feb 2, 2015
    2
    中文变量名。。。
    snachx
    snachx
    Feb 3, 2015
    3
    @letv 中文只是lz的叙述过程。。。
    zerh925
    zerh925
    Feb 3, 2015
    4
    学好语文再来提问
    xwsoul
    xwsoul
    Feb 3, 2015❤️1
    5
    @zerh925 提问者不是问的很清楚了么...
    @hitluobin 按字符分组(itertools.groupby, 空格也算), 每组字符最多取两个 [:2] 合并为字符串, 将各组字符串合并为一个字符串
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1464 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:16 · PVG 19:16 · LAX 03:16 · JFK 06:16
    ♥ Do have faith in what you're doing.