一collection模块
from collections import namedtuplepoint=namedtuple('point',['x','y'])p=point(1,2)print(p.x)print(p.y)from collections import dequeq=deque(['a','b','c'])q.append('x')q.appendleft('y')print(q)q.popleft()print(q)from collections import OrderedDicts1=dict([('a',1),('b',2),('c',3)])s=OrderedDict([('a',1),('b',2),('c',3)])print(s)print(s1)from collections import defaultdictvalues=[11,22,33,44,55,66,77,88,99,90]my_dict=defaultdict(list)for value in values: if value>66: my_dict['k1'].append(value) else: my_dict['k2'].append(value)print(my_dict)from collections import Counters=Counter('aabbddffeecc')print(s)random模块import random任意小数print(random.random())print(random.uniform(1,3))任意整数print(random.randint(1,5))print(random.randrange(1,5,2))随机返回一个任意数print(random.choice([1,'2',[2,3]]))print(random.sample([1,'2',[2,3]],3))item=[1,2,3,4,5,6]random.shuffle(item)print(item)re模块import reret=re.findall('a','aaabsoulsalt')print(ret)ret=re.search('a','aaabsoulsalt').group()print(ret)ret=re.match('a','abbcc').group()print(ret)ret=re.split('[a,b]','abcde')print(ret)ret=re.sub('\d','h','abcde123',1)print(ret)ret=re.sub('\d','h','abcde123')print(ret)打印扑克牌花色from collections import namedtuplepoint=namedtuple('point',['x','y'])for x in range(1,14): if x==11:x='J' if x == 12: x = 'Q' if x == 13: x = 'K' for y in ('黑桃','红桃','梅花','方片'): p=point(x,y) print(p)