[三个版本]自定义int()函数(Python实现)
来源:互联网 发布:返利网淘宝卖家知道吗 编辑:程序博客网 时间:2024/06/04 19:15
代码一:
from functools import reducedef int(string): def f(x, y): return x*10 + y def m(c): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8,'9': 9}[c] return reduce(f, map(m, string))
代码二:
from functools import reducedef int(string): def f(x, y): return x*10 + y return reduce(f, map(lambda x: ord(x) - ord('0'), string))
代码三:
from functools import reducedef int(string): return reduce(lambda x, y: x*10 + y, map(lambda x: ord(x) - ord('0'), string))
阅读全文
0 0
- [三个版本]自定义int()函数(Python实现)
- python-------------自定义str转换成int的函数
- MySQL自定义函数的Windows版本实现
- Python函数-int()
- python: int函数
- 【Python】使用reduce和map函数实现str转int
- python自定义函数实现最大值的输出
- python自定义函数实现最大值的输出
- 利用成员函数、友元函数和一般函数,实现三个版本的求两点间距离的函数
- 自定义版本比较函数
- Python int()函数 基础知识篇
- Power(int base, int exponent) 函数实现
- Python--函数,自定义函数
- C++三个函数实现精美图片
- 矩阵乘法的三个版本实现
- 编写函数,将三个int型整数按升序排列
- Android自定义控件三个构造函数
- Android自定义控件三个构造函数
- C++ 动态内存
- ClassLoader知识
- MySQL (二) 字符 DML DDL
- Linux system 4
- Java基本类型,默认取值,取值范围,数据转换
- [三个版本]自定义int()函数(Python实现)
- 清北学堂 2017-10-06
- CSDN-markdown编辑器语法
- 一张图讲解对象锁和关键字synchronized修饰方法(代码块)
- 1004. 成绩排名 (20)
- 欧拉回路与欧拉道路
- 卷积的使用
- JQuery EasyUI学习总结
- Linux-USB总线驱动分析