python3 7 day
如果一个可迭代对象的元素个数超过变量个数时,会出现”太多解压值”的异常。 那么怎样才能从这个可迭代对象中解压出N个元素出来?
结合*使用
>>> info=('hy','21','598779784','network') >>> name,*other,master=info >>> name 'hy' >>> master 'network' >>> other ['21', '598779784']
>>> *_else,tail=[3,5,8,0] >>> _else [3, 5, 8] >>> tail 0
在队列两端插入或删除元素时间复杂度都是O(1),而在列表的开头插入或删除元素的时间复杂度为O(N)?
>>> from collections import deque >>> q = deque(maxlen=3) >>> q.append(1) >>> q.append(2) >>> q.append(3) >>> q deque([1, 2, 3], maxlen=3) >>> q.append(4) >>> q deque([2, 3, 4], maxlen=3) >>> q.pop() 4 >>> q deque([2, 3], maxlen=3) >>> q.popleft() 2 >>> q deque([3], maxlen=3)
谢谢