<jupyter_start><jupyter_text>Stack and Queues in Python Data structures organize storage in computers so that we can efficiently access and change data. Stacks and Queues are some of the earliest data structures defined in computer science. StackStacks, like the name suggests, follow the **Last-in-First-Out (LIFO)** principle. It is a linear data structure which follows a particular order in which the operations are performed. As if stacking plates one on top of the other, the last plate we put on the top is the one that is the first to be removed from the stack later. Basic operations you can perform in a stack - **`Push`** - Adds an element to the top of the stack.- **`Pop`** - Removes the element at the top of the stack.- **`Peek`** or **`top`** - Look at the top of the stack  Implementing Stack using list<jupyter_code>stack = []<jupyter_output><empty_output><jupyter_text>Function to print top element of stack<jupyter_code>def top(stack):
    if stack != []:
        print("{} is top element".format(stack[-1]))
    else:
        print("Stack Empty!!!")<jupyter_output><empty_output><jupyter_text>Function to print size of stack<jupyter_code>def size(stack):
    print("Size of stack is {}".format(len(stack)))<jupyter_output><empty_output><jupyter_text>Function to check if a stack is empty<jupyter_code>def empty(stack):
    if stack == []:
        return True
    else:
        return False<jupyter_output><empty_output><jupyter_text>Function to `Push` element into stack<jupyter_code>def push(stack, value):
    stack.append(value)
    print("Pushed {} into stack".format(value))<jupyter_output><empty_output><jupyter_text>Function to `Pop` elements from stack<jupyter_code>def pop(stack):
    if not empty(stack):
        print("{} is popped".format(stack.pop()))
    else:
        print("Cannot Pop since stack is empty")<jupyter_output><empty_output><jupyter_text>Function to print the complete stack<jupyter_code>def show_stack(stack):
    print("Full stack is {}".format(stack))<jupyter_output><empty_output><jupyter_text>Taking Stacks out for a spin<jupyter_code># Pushing elements into a stack
push(stack, 1)
push(stack, 2)
push(stack, 3)

# Printing stack
show_stack(stack)

# Printing stack size
size(stack)

# Printing top of stack
top(stack)

# Popping elements from a stack
pop(stack)

show_stack(stack) 

# Check if stack is empty
empty(stack)

# More popping elements from a stack
pop(stack)
pop(stack)
# The below line would fail since there are no more elements to pop from a stack
pop(stack)

show_stack(stack)

empty(stack)<jupyter_output>Pushed 1 into stack
Pushed 2 into stack
Pushed 3 into stack
Full stack is [1, 2, 3]
Size of stack is 3
3 is top element
3 is popped
Full stack is [1, 2]
2 is popped
1 is popped
Cannot Pop since stack is empty
Full stack is []
{'fraction_non_alphanumeric': 0.09632536567962897, 'fraction_numerical': 0.006064930431680342, 'mean_word_length': 4.890756302521009, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '338747', 'license': 'CC0-1.0', 'n_tokens_mistral': 879, 'n_tokens_neox': 863, 'n_words': 336, 'path': 'Python - Stacks and Queues.ipynb', 'repo_name': 'bearlike/CBSE-Computer-Science', 'size': '2803'}