推荐学习书目
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 · 4348 views
    This topic created in 4122 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
        1
    Shared  
       Feb 2, 2015   ❤️ 1
    查 itertools 的 groupby 用法
    letv
        2
    letv  
       Feb 2, 2015
    中文变量名。。。
    snachx
        3
    snachx  
       Feb 3, 2015
    @letv 中文只是lz的叙述过程。。。
    zerh925
        4
    zerh925  
       Feb 3, 2015
    学好语文再来提问
    xwsoul
        5
    xwsoul  
       Feb 3, 2015   ❤️ 1
    @zerh925 提问者不是问的很清楚了么...
    @hitluobin 按字符分组(itertools.groupby, 空格也算), 每组字符最多取两个 [:2] 合并为字符串, 将各组字符串合并为一个字符串
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3228 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 14:43 · PVG 22:43 · LAX 07:43 · JFK 10:43
    ♥ Do have faith in what you're doing.