Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
from collections import deque q = deque() q.append('10') # push q.append('20') # push q.append('30') # push print(q) # deque(['10', '20', '30']) print(q.pop()) # pop # 30 print(q.pop()) # pop # 20 print(q) # deque(['10'])
from collections import deque q = deque() q.append('10') # push q.append('20') # push q.append('30') # push print(q) # deque(['10', '20', '30']) print(q.pop()) # pop # 30 print(q.pop()) # pop # 20
class Stack: def __init__(self): self.stack = [] def push(self, item): self.stack.append(item) def pop(self): self.stack.pop() def get(self): return self.stack if __name__ == '__main__': stack = Stack() stack.push(1) stack.push(2) stack.push(3) print(stack.get()) stack.pop() print(stack.get())
class Stack: def __init__(self): self.stack = [] def push(self, item): self.stack.append(item) def pop(self): self.stack.pop() def get(self): return self.stack def get_even(self): return [item for item in self.stack if item % 2 == 0] def get_uneven(self): return [item for item in self.stack if item % 2 != 0] if __name__ == '__main__': stack = Stack() stack.push(1) stack.push(2) stack.push(3) stack.push(4) print(stack.get_even()) print(stack.get_uneven())