“Stapel in Python” Code-Antworten

Python -Stack -Datenstruktur

>>> from collections import deque
>>> myStack = deque()
>>> myStack.append('a')
>>> myStack.append('b')
>>> myStack.append('c')
>>> myStack
deque(['a', 'b', 'c'])
>>> myStack.pop()
'c'
>>> myStack
deque(['a', 'b'])
Kodi4444

Stapel in Python

# Python program to
# demonstrate stack implementation
# using list
  
stack = []
  
# append() function to push
# element in the stack
stack.append('a')
stack.append('b')
stack.append('c')
  
print('Initial stack')
print(stack)
  
# pop() function to pop
# element from stack in
# LIFO order
print('\nElements popped from stack:')
print(stack.pop())
print(stack.pop())
print(stack.pop())
  
print('\nStack after elements are popped:')
print(stack)
  
# uncommenting print(stack.pop())
# will cause an IndexError
# as the stack is now empty
bongani mguni

Ähnliche Antworten wie “Stapel in Python”

Fragen ähnlich wie “Stapel in Python”

Weitere verwandte Antworten zu “Stapel in Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen