Ray's playground

 

Recipe 1.1. Processing a String One Character at a Time(Python Cookbook)

set
1 >>> import sets
2 >>> magic_chars = sets.set('abracadabra')
3 >>> magic_chars = sets.Set('abracadabra')
4 >>> poppins_chars = sets.Set('supercalifragilisticexpialidocious')
5 >>> print ''.join(magic_chars & poppins_chars)
6 acrd

 

1 >>> def fun(c):
2     print c
3     
4 >>> map(fun, "abc")
5 a
6 b
7 c
8 [None, None, None]

 

 

posted on 2010-12-15 21:52  Ray Z  阅读(162)  评论(0编辑  收藏  举报

导航