collection模块

from collections import namedtuple
# 具名元组 (具有名字的元组)
a = (1,2)
p = namedtuple('坐标',['x','y'])
p = namedtuple('坐标','x y z')
location1 = p(1,2,3) # 元素的个数一定要跟上面第二个参数的个数相同
print(location1)
print(location1.x)
print(location1.y)
print(location1.z)
card = namedtuple('扑克牌',['color','number'])
A = card('♠','A')
print(A)
print(A.color)
print(A.number)
#
city = namedtuple('日本',['countryname','name','gender','size'])
c = city('东京','冲老师','female','L')
print(c)


from collections import deque
"""
双端队列
:队列是一端放值,一端取值,就是管道,而这个双端队列是两端都可取和放
append :右边放
appendleft:左边放

pop:右边弹出
# popleft:左边弹出
# """
q = deque()
q.append(1)
q.appendleft(2)
print(q.pop())
print(q.popleft())
print(q)
from collections import Counter
res = 'abcdeabcdabcaba'
res1 = Counter(res)
print(res1.get('a'))
原文地址:https://www.cnblogs.com/1832921tongjieducn/p/11312608.html