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

以下迭代如何改为函数式?

  •  
  •   zungmou · Mar 8, 2017 · 2874 views
    This topic created in 3510 days ago, the information mentioned may be changed or developed.

    Python 代码

    def parse(self, data):
        tmp = data
        # funcs is a callable function iterator
        for func in funcs:
            tmp = func(tmp)
        return tmp
    
    5 replies  •  2017-03-08 21:13:51 +08:00
    yeyuexia
        1
    yeyuexia  
       Mar 8, 2017   ❤️ 1
    reduce(lamda x, y: y(x), funcs, data)
    staticor
        2
    staticor  
       Mar 8, 2017
    递归实现 判断 funcs
    eccstartup
        3
    eccstartup  
       Mar 8, 2017
    funs = [(+1),(*2),(subtract 3)]
    f = foldr (flip (.)) id funs
    f 1
    zungmou
        4
    zungmou  
    OP
       Mar 8, 2017
    @eccstartup 您这不是 Python 代码呀
    zhzy0077
        5
    zhzy0077  
       Mar 8, 2017 via Android   ❤️ 1
    (fold-left (λ (tmp, func) (func tmp)) data funcs)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2671 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 15:49 · PVG 23:49 · LAX 08:49 · JFK 11:49
    ♥ Do have faith in what you're doing.