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

这段代码为什么会返回空 set

  •  
  •   scalaer · Jul 30, 2019 · 1613 views
    This topic created in 2615 days ago, the information mentioned may be changed or developed.
    from functools import reduce
    
    print({1, 2} & {2, 3})
    print(reduce(lambda x, y: x & y, [{1, 2}, {3, 4}, {2, 3}]))
    

    output:

    {2}
    set()
    
    itskingname
        1
    itskingname  
       Jul 30, 2019
    因为首先是{1, 2} & {3, 4}结果为{},然后{} & {2, 3}结果依然为{}
    scalaer
        2
    scalaer  
    OP
       Jul 30, 2019
    @itskingname 😯, 我蠢了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   838 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:14 · PVG 05:14 · LAX 14:14 · JFK 17:14
    ♥ Do have faith in what you're doing.