<jupyter_start><jupyter_text>Python BasicsThis is a collection of exercises that I wrote as a refresher of key Python features. Built-in datatypes and variable bindingPython uses dynamic typing. This means that the type of data in a variable is not explicitly identified in a program, like it is in C++ or Java."  ints and floats  booleanPython's boolean values are True and False. It is case-sensitive: capitalizing the first letter is required.   Strings  Lists and tuples<jupyter_code>#shortcut for list of consecutive integers

#slices

#List comprehension
# create a list of squares for integers 0 to 9

# create a list of tuples (x, x*x) for integers 0 to 9

# create a list of tuples (x, x*x, x**3) for integers 0 to 9<jupyter_output>[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25), (6, 36), (7, 49), (8, 64), (9, 81)]
[(0, 0, 0), (1, 1, 1), (2, 4, 8), (3, 9, 27), (4, 16, 64), (5, 25, 125), (6, 36, 216), (7, 49, 343), (8, 64, 512), (9, 81, 729)]<jupyter_text>Looping (for, while, reduce)<jupyter_code>#for
#sum integers from 1 to 100

#while
#sum integers from 1 to 100


#concise way to sum integers from 1 to 100 using reduce

import functools

#use the sum function

#preferred way to sum floating point (faster) using fsum<jupyter_output>5050.0<jupyter_text>Conditional execution (if)<jupyter_code>#if<jupyter_output>0.9724236150833007 is above median<jupyter_text>Dictionaries<jupyter_code>#distribution of characters in a string
s = "The quick brown fox jumps over the lazy dog."<jupyter_output>{'T': 1, 'h': 2, 'e': 3, ' ': 8, 'q': 1, 'u': 2, 'i': 1, 'c': 1, 'k': 1, 'b': 1, 'r': 2, 'o': 4, 'w': 1, 'n': 1, 'f': 1, 'x': 1, 'j': 1, 'm': 1, 'p': 1, 's': 1, 'v': 1, 't': 1, 'l': 1, 'a': 1, 'z': 1, 'y': 1, 'd': 1, 'g': 1, '.': 1}<jupyter_text>Functions<jupyter_code>def factorial(n):
    ...
for n in range(0,5):
    print(str(n) +"! =", factorial(n))
def gcd(a, b):
    ...

print(gcd(144, 256))<jupyter_output>16
{'fraction_non_alphanumeric': 0.17293997965412003, 'fraction_numerical': 0.08646998982706001, 'mean_word_length': 4.479108635097493, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '366335', 'license': 'MIT', 'n_tokens_mistral': 932, 'n_tokens_neox': 771, 'n_words': 303, 'path': 'Python/python-basics-notebook.ipynb', 'repo_name': 'Alfred-Li-um/Alfred-Li-um.github.io', 'size': '1966'}