![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
markapril
这个作者很懒,什么都没留下…
展开
-
Recipe 2.16. Walking Directory Trees
import osimport fnmatchdef all_files(path, patterns='*', single_level=False, yield_fold=True): patterns = patterns.split(";") for root原创 2011-07-17 14:18:19 · 279 阅读 · 0 评论 -
Recipe 4.10. Adding an Entry to a Dictionary
def addword(theIndex, word, pagenumber): theIndex.setdefault(word, [ ]).append(pagenumber)原创 2011-07-17 23:47:49 · 277 阅读 · 0 评论 -
Replacing Multiple Patterns in a Single Pass
import osimport redef replace_mlt(text, adict): reobj = re.compile('|'.join(map(re.escape, adict))) def repl(maobj): return adi原创 2011-07-17 01:19:05 · 335 阅读 · 0 评论 -
Recipe 4.8. Transposing Two-Dimensional Arrays
arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]print map(list, zip(*arr))原创 2011-07-17 23:06:18 · 212 阅读 · 0 评论 -
Recipe 5.2. Sorting a List of Strings Case-Insensitively
def case_insensitive_sort(string_list): auxiliary_list = [(x.lower( ), x) for x in string_list] # decorate auxiliary_list.sort( )原创 2011-07-18 22:37:52 · 268 阅读 · 0 评论 -
Recipe 5.10. Selecting the nth Smallest Element of a Sequence
SolutionPerhaps you can do better, if the sequence is big, has been shuffled enough, and comparisons between its items are costly. Sort is v原创 2011-07-19 00:14:06 · 218 阅读 · 0 评论 -
Recipe 5.11. Showing off quicksort in Three Lines
Functional programming languages, of which Haskell is a great example, are splendid animals, but Python can hold its own in such company:def原创 2011-07-19 00:19:06 · 301 阅读 · 0 评论 -
python时间转换
>>> time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1317393879.0)) '2011-09-30 22:44:39'>>> >>> time.mktime(time.strptime('2011-09-30 22:44:39', '%Y-%m-%d %H:%M:%S'原创 2011-11-19 10:54:54 · 338 阅读 · 0 评论 -
Python面向函数编程——装饰器的实际应用
转载来源:http://1.python123.sinaapp.com/?p=67 所有版权归原作者所有对某个函数使用了装饰器之后,实际上是改变了函数的代码入口点。也就是变成了装饰器函数所返回的函数的代码入口点了。 机制 装饰器之所以能够工作,是因为Python是一个动态语言。函数是作为第一级对象存在的,就是说函数可以存储到变量中、作为参数传递给其他函数,最重转载 2011-11-23 00:55:12 · 1391 阅读 · 0 评论