astring="Hello world!"
revwords = astring.split() # string -> list of words
revwords.reverse( ) # reverse the list in place
revwords = ' '.join(revwords) # list of strings -> string
print revwords
revwords = ' '.join(astring.split( )[::-1])
print revwords
#1.8 判断一个list中的元素是否在一个集合中
def containsAny(seq, aset):
for c in seq:
if c in aset: return True
return False
import itertools
def containsAny(seq, aset):
for item in itertools.ifilter(aset.__contains__, seq):
return True
return False
#ifilter( predicate, iterable)
#Make an iterator that filters elements from iterable returning only those for which the predicate is True.
#If predicate is None, return the items that are true.
print bool(set(['a','b']).intersection(set(['b','d'])))