Advertisement
WupEly

Untitled

Apr 27th, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class Queue:
  2. def __init__(self, *values):
  3. self.q = list(values)
  4.  
  5. def __str__(self):
  6. q = ' -> '.join(map(str, self.q))
  7. return f'[{q}]'
  8.  
  9. def __next__(self):
  10. n = self.q[1:]
  11. return Queue(*n)
  12.  
  13. def __eq__(self, other):
  14. return self.q[:] == other.q[:]
  15.  
  16. def __add__(self, other):
  17. return Queue(*(self.q + other.q))
  18.  
  19. def __rshift__(self, other):
  20. n = self.q[other:]
  21. return Queue(*n)
  22.  
  23. def __iadd__(self, other):
  24. self.q += other.q
  25. return self
  26.  
  27. def extend(self, queue):
  28. self.q.extend(queue.q)
  29.  
  30. def append(self, *values):
  31. self.q += list(values)
  32.  
  33. def copy(self):
  34. return Queue(*self.q)
  35.  
  36. def pop(self):
  37. return self.q.pop(0)
  38.  
  39. def next(self):
  40. n = self.q[1:]
  41. return Queue(*n)
  42.  
  43. q1 = Queue(*range(1, 5))
  44. print(q1)
  45. q1.append(*range(5, 7))
  46. print(q1)
  47. q2 = q1 >> 3
  48. print(q1)
  49. print(q2)
  50. q3 = q1 >> 20
  51. print(q3)
  52. q4 = q1
  53. q1 += q2
  54. print(q1)
  55. print(q4)
  56. print(q1 + q4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement