首页 > 编程语言 > 详细

python高阶函数式编程

时间:2016-09-21 12:49:25      阅读:174      评论:0      收藏:0      [点我收藏+]
from functools import reduce

def str2int(s):
    def fn(x, y):
        return x * 10 + y
    def char2num(s):
        return {‘0‘: 0, ‘1‘: 1, ‘2‘: 2, ‘3‘: 3, ‘4‘: 4, ‘5‘: 5, ‘6‘: 6, ‘7‘: 7, ‘8‘: 8, ‘9‘: 9}[s]
    return reduce(fn, map(char2num, s))

我觉得这个函数写得很好,感觉很新颖;所以,记录下来。

希望自己的编程能力可以有所提高,通过不断的学习。

20160921

python高阶函数式编程

原文:http://www.cnblogs.com/xiaohaillong/p/5892064.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!