<jupyter_start><jupyter_text>Tuples as Data Structures<jupyter_code>(10, 20, 30,)
a = (10, 20, 30)
type(b)
def print_tuple(t):
    for e in t:
        print(e)
print_tuple(10, 20, 30)
print_tuple((10, 20, 30))
a = 'a', 10, 200
a[0]
a[1]
a = 1, 2, 3, 4, 5, 6
type(a)
a[2:5]
for e in a:
    print(e)
a = 'a', 10, 20
x, y, z = a
x
z
a = 1, 2, 3, 4, 5
x, *other, y, z = a
x
y
z
other
x, *_, y, z =a
x, y, z
_
a
a[0]= 100
class Point2D:
    def __init__(self, x, y):
        self.x = x
        self.y = y

def __repr__(self):
    return f'{self.__class__.__name__}(x={self.x}, y={self.y})'
pt = Point2D(10, 20)
pt
pt.x = 100
pt
id(pt)
a = Point2D(0, 0), Point2D(10, 20)
a
id(a[0])
a
s = 'python'
s = 'python' + ' rocks!'
s
id(s)
a = 1, 2, 3
id(a)
a += (4, 5)
a
id(a)
a = a+ (4, 6)
pt1 = (0, 0)
pt2 = (10, 20)
london = 'London', 'UK', 8_780_000
new_york = 'New York', 'USA', 8_500_000
beijing = 'Beijing', 'China', 21_000_000
london
cities = [london, new_york, beijing]
total = 0
for city in cities:
    total += city[2]
    print(total)
[city[2] for city in cities]
sum(city[2] for city in cities)
record = 'DJIA', 2018, 1, 19, 25_987, 26_072, 25_942, 26_072
symbol, year, month, day, open , high, low, close = record
symbol
close
symbol, *_, close = record
symbol, close
print(_)
for city in cities:
    print(city)
for city, country, population in cities:
    print(city, country, population)
for item in enumerate(cities):
    print(item)
for index, city in enumerate(cities):
    print(index, city)
from random import uniform
from math import sqrt

def ramdom_shot(radius):
    random_x = uniform(-radius, radius)
    random_y = uniform(-radius, radius)

    if sqrt(random_x **2 + random_y ** 2) <= radius:
        is_in_circle = True
    else:
        is_in_circle = False
        
    return random_x, random_y, is_in_circle
num_attemps = 1_000_000
count_inside = 0
for i in range(num_attemps):
    *_, is_in_circle = random_shot(1)
    if is_in_circle:
        count_inside += 1

print(f'Pi is approximately: {4 * count_inside / num_attemps}')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15173410404624277, 'fraction_numerical': 0.07273603082851637, 'mean_word_length': 3.476293103448276, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '227858', 'license': 'Unlicense', 'n_tokens_mistral': 1003, 'n_tokens_neox': 881, 'n_words': 277, 'path': 'my_classes/Tuples/tuples_as_data_structures.ipynb', 'repo_name': 'minefarmer/deep-Dive-1', 'size': '2076'}