- 浏览: 242712 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (127)
- vim (3)
- python (44)
- pymysql (1)
- mysql (9)
- macvim (1)
- erlang (3)
- twisted (0)
- tornado (5)
- django (7)
- postgresql (5)
- sql (1)
- java (7)
- tech (4)
- cache (1)
- lifestyle (3)
- html (1)
- ubuntu (2)
- rabbitmq (1)
- algorithm (8)
- Linux (4)
- Pythonista (1)
- thread (1)
- sort (6)
- 设计模式 (1)
- search (1)
- Unix (6)
- Socket (3)
- C (2)
- web (1)
- gc (1)
- php (10)
- macos (1)
最新评论
-
2057:
这个程序有bug。
查找算法学习之二分查找(Python版本)——BinarySearch -
dotjar:
NB
一个Python程序员的进化[转]
1、enum
2、检查字符串是否是number
3、list取交集
4、两个list转成一个dict
5、singleton
第二种tornado IOLoop中使用的单例模式:
6、list排重
未完待续...
参考资料:
http://stackoverflow.com/questions/36932/whats-the-best-way-to-implement-an-enum-in-python
http://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-number-in-python
http://docs.python.org/2/library/stdtypes.html#str.isdigit
#!/usr/bin/env python # -*- coding:utf-8 -*- def enum(**enums): return type('Enum', (), enums) Gender = enum(MALE=0,FEMALE=1) print Gender.MALE print Gender.FEMALE
2、检查字符串是否是number
s='123456789' s.isdigit()#return True
3、list取交集
s=[1,2,3] w=[2,3,4] list(set(s).intersection(w))
4、两个list转成一个dict
dict(zip(a,b))
5、singleton
def singleton(cls): instances = {} def get_instance(): if cls not in instances: instances[cls] = cls() return instances[cls] return get_instance
第二种tornado IOLoop中使用的单例模式:
@staticmethod def instance(): """Returns a global IOLoop instance. Most single-threaded applications have a single, global IOLoop. Use this method instead of passing around IOLoop instances throughout your code. A common pattern for classes that depend on IOLoops is to use a default argument to enable programs with multiple IOLoops but not require the argument for simpler applications:: class MyClass(object): def __init__(self, io_loop=None): self.io_loop = io_loop or IOLoop.instance() """ if not hasattr(IOLoop, "_instance"): with IOLoop._instance_lock: if not hasattr(IOLoop, "_instance"): # New instance after double check IOLoop._instance = IOLoop() return IOLoop._instance
6、list排重
{}.fromkeys(list).keys()
未完待续...
参考资料:
http://stackoverflow.com/questions/36932/whats-the-best-way-to-implement-an-enum-in-python
http://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-number-in-python
http://docs.python.org/2/library/stdtypes.html#str.isdigit
发表评论
-
macos 10.9.2 clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command
2014-03-25 19:13 1735方法总是有的,当然需要你去寻找。 当然如果花费太多的时间在一件 ... -
PostgreSQL psycopg2:IndexError: tuple index out of range
2014-01-09 17:04 2196Postgresql psycopg2使用like查询的时候 ... -
Python 迭代器和生成器
2013-10-15 23:09 2817迭代器 迭代器只不过是一个实现迭代器协议的容器对象。它基于两个 ... -
Python时间模块
2013-10-15 23:03 3434time模块 时间模块中最常用的一个函数就是获取当前时间的函数 ... -
Python装饰器
2013-10-15 22:59 1521编写自定义装饰器有许多方法,但最简单和最容易理解的方法是编写一 ... -
python list
2013-10-15 22:56 1221简单总结以及整理如下: >>> dir( ... -
Python Excel
2013-09-10 17:21 942安装lib easy_install xlrd def ... -
排序算法学习(python版本)之堆排序(HeapSort)
2013-07-01 22:54 1966Contains: 堆排序以及堆排序的应用 堆排序(Heaps ... -
python range xrange
2013-06-25 23:30 1107引用Help on built-in function ran ... -
python class
2013-06-25 00:54 1794引用类是创建新对象类 ... -
AttributeError: 'module' object has no attribute 'SendCloud'
2013-06-05 11:46 7031网上查了下 意思是说你命名的文件名不能和lib重名,这样会导 ... -
python string
2013-05-07 23:44 2171如果这就是字符串,这本来就是字符串 首先看下字符串的方法 ... -
Python property
2013-03-29 19:56 0由于之前有总结过,可以参考http://2057.iteye. ... -
python decorators
2013-03-28 23:36 1331Contains: 1、decorators 2、funct ... -
python closures
2013-03-28 22:09 1163Closure:如果在一个内部函数里,对在外部作用域(但不是在 ... -
Python map、filter,reduce介绍
2013-03-28 22:02 12541、filter(function,iterable) 引用C ... -
Python __new__ 、__init__、 __call__
2013-03-26 23:49 5307Contains: __new__: 创建对象时调用,返回当 ... -
Python socket简介
2013-03-25 23:42 2126自豪地使用dir和help. Python 2.7.2 ( ... -
Tornado ioloop源码简析
2013-03-21 00:18 2808#!/usr/bin/env python #-*-en ... -
Tornado httpserver 源码简析
2013-03-17 01:49 1752整个流程就是创建一个socket socket.socket ...
相关推荐
Python Tips 一些初学者到中级用户的Python技巧
pythonTips 上的题解 LeetCode主页:.已做题目数: 47 力码 数字 标题 困难 语 运行 头脑 01 二和 简单的 1138ms/34.16% 列表转字典,哈希表 07 反转整数 简单的 Java 33 毫秒/5.42% 09 回文数 简单的 Java 154ms/...
利用Python进行数据分析,小费数据集。
各种python小技巧: 1. 列表相减: 列表A是一个完整轨迹,B是已走过的轨迹,求剩下的轨迹 # A: ['a','b','c','d'] # B: ['a','b'] In [89]: A = ['a','b','c','d'] In [90]: B = ['a','b'] In [92]: [x for x ...
此仓库包含在发布的所有教程 ####编辑 我已经有一段时间没有更新这个仓库了。
Python技巧与窍门有关Python的一些技巧和窍门。有用的文件-BeautifulSoup库的概述,以便解析XML文件。 -概述Oletools库,以便检查VB代码 -Pyspark库概述-Sweetviz库概述帮助您找到所有缺少的值并显示它们-获取文件的...
五个Python编程Tips,帮你提高编码效率.doc
Data-Wrangling-with-Python-Tips-and-Tools-to-Make-Your-Life-Easier.pdf
Packed with Useful Hints and Tips You'll learn the best practices without wasting time searching or trying to force Python to be like other languages. I've collected all the gems I've gleaned over ...
An indispensable collection of practical tips and real-world advice for tackling common Python problems and taking your code to the next level. Features interviews with high-profile Python developers ...
python数据分析案例数据 主要用于本人博客的部分文章案例数据使用。 单变量的样本分布检验(python3) 探索变量间关系 ....... 等文章的案例数据
The main goal of this book is to provide tips to Python developers of various levels so they can write better Python software and programs. This book gives you various techniques irrespective of the ...
python练习数据。机器人理财是将人工智能导入传统的理财顾问服务,并非由实体的机器人帮助客户理财,而是透过网络线上互动,依据需求者设定的投资目的及风险承受度,透过计算机程序的算法,提供自动化的投资组合建议...
Quickly learn how to automate unit testing of Python 3 code with Python 3 automation libraries, such as doctest, unittest, nose, nose2, and pytest. This book explores the ...Chapter 6: Tips and Tricks
使用Python实现自动化邮件发送,可以让你摆脱繁琐的重复性业务,可以节省非常多的时间。我们把报表做出来以后一般都是需要发给别人查看,对于一些每天需要发的报表或者是需要一次发送多份的报表,这个时候可以考虑...
这个项目是为了给KBEngine服务端编写Python脚本的时候,让IDE有语法提示。
Data Wrangling with Python 全面掌握用Python进行爬虫抓取以及数据清洗与分析的方法 轻松实现高效数据处理 https://item.jd.com/12219342.html
Python developers looking for tips on how to create illustrations and visualizations, as well as scientists, engineers, or students using Python. It assumes familiarity with vectors, matrices, ...
收录python基础库中sys、pathlib、arrow、configParser等基础库的用法,以及其它基础知识
These fun and easy tips transform the dreaded chore of learning a new programming language into a fun process. You'll be proud to show off your new skills to your friends and family! What are the ...