SHARE
TWEET

Untitled

a guest Sep 17th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Deque:
  2.     def __init__(self):
  3.         self.lst = []
  4.  
  5.     def push_front(self, element):
  6.         self.lst.insert(0, element)
  7.  
  8.     def push_back(self, element):
  9.         self.lst.append(element)
  10.  
  11.     def pop_front(self):
  12.         return self.lst.pop(0)  # .pop удаляет элемент с конца если в скобочках не указан элемент (тут удаляет элемент с начала)
  13.  
  14.     def pop_back(self):
  15.         return self.lst.pop()  # .pop удаляет элемент с конца если в скобочках не указан элемент УДАЛЯЕМ BACK ЭЛЕМЕНТ
  16.  
  17. deque = Deque()
  18. while True:
  19.     lst = [str(x) for x in input().split(' ')]
  20.     if lst[0] == 'push_front':
  21.         deque.push_front(lst[1])
  22.         print('ok')
  23.     elif lst[0] == 'push_back':
  24.         deque.push_back(lst[1])
  25.         print('ok')
  26.     elif lst[0] == 'pop_front':
  27.         print(deque.lst[0])
  28.         deque.pop_front()
  29.     elif lst[0] == 'pop_back':
  30.         print(deque.lst[-1])
  31.         deque.pop_back()
  32.     elif lst[0] == 'front':
  33.         print(deque.lst[0])
  34.     elif lst[0] == 'back':
  35.         print(deque.lst[-1])
  36.     elif lst[0] == 'size':
  37.         print(len(deque.lst))
  38.     elif lst[0] == 'clear':
  39.         deque.lst.clear()
  40.         print('ok')
  41.     elif lst[0] == 'exit':
  42.         print('bye')
  43.         break
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top