Skip to content

Commit e1f42dc

Browse files
committed
collections.deque: Speedup appendleft, implement __iter__ and __str__
1 parent 68f41ae commit e1f42dc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

collections.deque/collections/deque.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ def append(self, a):
1919
self.q.append(a)
2020

2121
def appendleft(self, a):
22-
self.q = [a] + self.q
22+
self.q.insert(0, a)
2323

2424
def __len__(self):
2525
return len(self.q)
2626

2727
def __bool__(self):
2828
return bool(self.q)
29+
30+
def __iter__(self):
31+
yield from self.q
32+
33+
def __str__(self):
34+
return 'deque({})'.format(self.q)

0 commit comments

Comments
 (0)