Python偏函数
来源:互联网 发布:诸宸的悲剧 知乎 编辑:程序博客网 时间:2024/05/29 09:18
任务
在第7节中,我们在sorted这个高阶函数中传入自定义排序函数就可以实现忽略大小写排序。请用functools.partial把这个复杂调用变成一个简单的函数:
sorted_ignore_case(iterable)
- ?不会了怎么办
要固定sorted()的cmp参数,需要传入一个排序函数作为cmp的默认值。
参考代码:
import functoolssorted_ignore_case = functools.partial(sorted, cmp=lambda s1, s2: cmp(s1.upper(), s2.upper()))print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
0 0
- python 偏函数应用
- Python中的偏函数
- [Python]偏函数应用
- python学习-偏函数
- python偏函数partial
- Python偏函数
- Python偏函数
- python偏函数
- python偏函数
- python 偏函数解析
- Python偏函数
- Python 偏函数
- python偏函数应用
- Python偏函数应用
- python的偏函数
- 自学Python day5--------函数编程(偏函数)
- python函数式编程之偏函数
- 【python】偏函数 functools partial
- poj 1163 The Triangle
- 实验一 离散时间序列卷积和MATLAB实现
- Labview与其他应用程序的接口设计
- OJ-多态性
- 深度学习及课题研究杂谈(一)
- Python偏函数
- Notification与Delegate实现通讯沙拉实例
- 算法——排序算法个人总结
- Android <include />用法
- struts2中json插件日期格式化
- qq连接代码生成总结
- Archlinux 修改/etc/profile文件使得ls等命令结果显示颜色
- 编程之美 2.9 斐波那契(Fibonacci)数列
- 通径分析