<jupyter_start><jupyter_text>Exercise 1<jupyter_code>big_list_of_numbers = [1 for x in range(0, 10000000)]

from sys import getsizeof
getsizeof(big_list_of_numbers)
from itertools import repeat
small_list_of_numbers = repeat(1, times=10000000)
getsizeof(small_list_of_numbers)
for i, x in enumerate(small_list_of_numbers):
    print(x)
    if i > 10:
        break<jupyter_output>1
1
1
1
1
1
1
1
1
1
1
1<jupyter_text>Exercise 2 (Stack)<jupyter_code>stack = []
stack.append(25)
stack
stack.append(-12)
stack
tos = stack.pop()
tos
stack
stack.append("Hello")
stack<jupyter_output><empty_output><jupyter_text>Exercise 3 (Stack, custom functions)<jupyter_code>def stack_push(s, value):
    return s + [value]

def stack_pop(s):
    tos = s[-1]
    del s[-1]
    return tos

url_stack = []
wikipedia_datascience = "Data science is an interdisciplinary field that uses scientific methods, processes, algorithms and systems to extract knowledge [https://en.wikipedia.org/wiki/Knowledge] and insights from data [https://en.wikipedia.org/wiki/Data] in various forms, both structured and unstructured,similar to data mining [https://en.wikipedia.org/wiki/Data_mining]"
len(wikipedia_datascience)
wd_list = wikipedia_datascience.split()
len(wd_list)
for word in wd_list:
    if word.startswith("[https://"):
        url_stack = stack_push(url_stack, word[1:-1])
url_stack
for i in range(0, len(url_stack)):
    print(stack_pop(url_stack))
print(url_stack)<jupyter_output>[]<jupyter_text>Exercise 4 (lambda expression)<jupyter_code>import math
def my_sine():
    return lambda x: math.sin(math.radians(x))

def my_cosine():
    return lambda x: math.cos(math.radians(x))
sine = my_sine()
cosine = my_cosine()
math.pow(sine(30), 2) + math.pow(cosine(30), 2)
# Sorting list of tuples
capitals = [("USA", "Washington"), ("India", "Delhi"), ("France", "Paris"), ("UK", "London")]
capitals
capitals.sort(key=lambda item: item[1])
capitals<jupyter_output><empty_output><jupyter_text>Exercise 5 (Multi Element membership checking)<jupyter_code>list_of_words = ["Hello", "there.", "How", "are", "you", "doing"]
check_for = ["How", "are"]
all(w in list_of_words for w in check_for)<jupyter_output><empty_output><jupyter_text>Exercise 6 (Queue with list and dqueue)<jupyter_code>queue = []
%%time
for i in range(0, 100000):
    queue.append(i)
print("Queue created")
for i in range(0, 100000):
    queue.pop(0)
print("Queue emptied")
%%time
from collections import deque
queue2 = deque()
for i in range(0, 100000):
    queue2.append(i)
print("Queue created")
for i in range(0, 100000):
    queue2.popleft()
print("Queue emptied")<jupyter_output>Queue created
Queue emptied
CPU times: user 30 ms, sys: 0 ns, total: 30 ms
Wall time: 27.8 ms
{'fraction_non_alphanumeric': 0.13438880706921943, 'fraction_numerical': 0.034977908689248896, 'mean_word_length': 5.843828715365239, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 23, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '570142', 'license': 'MIT', 'n_tokens_mistral': 1062, 'n_tokens_neox': 982, 'n_words': 255, 'path': 'Lesson02/Exercise15-21/List Exercises.ipynb', 'repo_name': 'RileyAfencl/DSC-540', 'size': '2716'}