分类:
2010-05-17 23:20:04
枚举
>>> for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter']):
... print i, season
0 Spring
1 Summer
2 Fall
3 Winter
过滤
>>> filter(lambda x:x%2,range(10))
[1, 3, 5, 7, 9]
# 其实 [x for x in range(10) if x%2 ]
zip
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> zipped
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zipped)
>>> x == list(x2) and y == list(y2)
True
execfile
execfile(filename[, globals[, locals]])