Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Queue:
- def __init__(self, *values):
- self.q = list(values)
- def __str__(self):
- q = ' -> '.join(map(str, self.q))
- return f'[{q}]'
- def __next__(self):
- n = self.q[1:]
- return Queue(*n)
- def __eq__(self, other):
- return self.q[:] == other.q[:]
- def __add__(self, other):
- return Queue(*(self.q + other.q))
- def __rshift__(self, other):
- n = self.q[other:]
- return Queue(*n)
- def __iadd__(self, other):
- self.q += other.q
- return self
- def extend(self, queue):
- self.q.extend(queue.q)
- def append(self, *values):
- self.q += list(values)
- def copy(self):
- return Queue(*self.q)
- def pop(self):
- return self.q.pop(0)
- def next(self):
- n = self.q[1:]
- return Queue(*n)
- q1 = Queue(*range(1, 5))
- print(q1)
- q1.append(*range(5, 7))
- print(q1)
- q2 = q1 >> 3
- print(q1)
- print(q2)
- q3 = q1 >> 20
- print(q3)
- q4 = q1
- q1 += q2
- print(q1)
- print(q4)
- print(q1 + q4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement