life is short, you need python
2016-04-09 13:52
471 查看
人事苦短,我用python。
这句话应该大部分都听过吧,意思就是体现了Python的简洁、明了。
没代码说个xx:
多线程:
>>> for thread in [ready, aim, fire]: >>> ... thread.start()
Fibonacci序列:
fib = lambda n: n if n < 2 else fib(n-1) + fib(n-2)
从list获取元素:
>>>alist = ['foo', 'foo', 'hello', 'hello', 'hello', 'bar'] >>>print list(set(alist))
unique特性:
x = [1,5,3,2] y = x y.sort() print x print y Output: [1,2,3,5] [1,2,3,5]
交换两个变量:
a,b = b,a
串联两个字典:
>>> dict_1 = {1: 'a', 2: 'b', 3: 'c'} >>> dict_2 = {4: 'd', 5: 'e', 6: 'f'} >>> dict_1 {1: 'a', 2: 'b', 3: 'c'} >>> dict_2 {4: 'd', 5: 'e', 6: 'f'} >>> dict_1.update(dict_2) >>> dict_2 {4: 'd', 5: 'e', 6: 'f'} >>> dict_1 {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f'}
相关文章推荐
- Python 练习实例3
- python小工具:检索目录大小
- python升级步骤
- filter 、map 、reduse、sorted 作用、特性及实例
- ubuntu14.04安裝numpy,scipy
- 关于unicode的学习
- sorted 函数
- 一个简单的Python爬虫
- python 装饰器
- python之路2
- python 安装numpy,scipy,matplotlib算法库
- python学习笔记(excel+requests)
- python tornado微信开发
- python 学习笔记3(循环方式;list初始化;循环对象/生成器/表推导;函数对象;异常处理)
- Python 练习实例2
- python 分页
- Python之路【第十八篇】Django小项目webQQ实现
- python中if __name__ == '__main__': 的解析
- Counting Bobs!
- python安装paramiko模块