Py&禅

博客园 首页 新随笔 联系 订阅 管理

06 2010 档案

摘要:Problem:如题Solution:一个简单的工厂类方法:import stringdef translator(frm='', to='', delete='', keep=None) if len(to)=1: to = to * len(frm) trans = string.maketrans(frm, to) if keep is not None: allchars = string... 阅读全文
posted @ 2010-06-05 11:33 Py&禅 阅读(263) 评论(0) 推荐(0)

摘要:Problem:检查字符串中是否存在某些字符的集合Solution:下面的方法可以用在任何的序列容器中def containsAny(seq, aset): """ Check whether sequence seq contains ANY of the items in aset. """ for c in seq: if c in aset: return True return Fals... 阅读全文
posted @ 2010-06-01 13:04 Py&禅 阅读(223) 评论(0) 推荐(0)

摘要:# -*- coding:utf-8 -*-"""Created on 2010-5-21单链表的实现 1@author: Administrator"""class LinkedList(object): class Element(object): ''' 定义元素,包含了数据内容_datum和指向下一元素的链接_next ''' def __init__(self,list,datum... 阅读全文
posted @ 2010-06-01 05:37 Py&禅 阅读(337) 评论(0) 推荐(0)