Skip to content

Instantly share code, notes, and snippets.

View bee-san's full-sized avatar
🌻
Tending to my plants

Autumn (Bee) bee-san

🌻
Tending to my plants
View GitHub Profile
x = [1, 2, 3, 4, 5]
def square(num):
return num*num
print(list(map(square, x)))
map(function, iterable)
for c in Counter(3, 8):
print(c)
class Counter:
def __init__(self, low, high):
# set class attributes inside the magic method __init__
# for "inistalise"
self.current = low
self.high = high
def __iter__(self):
# first magic method to make this object iterable
return self
def factorial_recursive(n):
# Base case: 1! = 1
if n == 1:
return 1
# Recursive case: n! = n * (n-1)!
else:
return n * factorial_recursive(n-1)
a = 3
def some_func():
global a
a = 5
some_func()
print(a)
@bee-san
bee-san / timsort.py
Last active August 15, 2021 10:28
An Python implementation of Timsort
# based off of this code https://gist.github.com/nandajavarma/a3a6b62f34e74ec4c31674934327bbd3
# Brandon Skerritt
# https://skerritt.tech
def binary_search(the_array, item, start, end):
if start == end:
if the_array[start] > item:
return start
else:
return start + 1
@bee-san
bee-san / DeployBot.py
Created June 16, 2018 09:40
Find all the HTTP 404 and similar errors on a website
# Deploy bot for Python
# TODO
# check all links on page for 404
import check_link
from bs4 import BeautifulSoup
import urllib.request
from multiprocessing import Process
# creates a global check_link object
import collections
Card = collections.namedtuple('Card', ['rank', 'suit'])
class FrenchDeck:
ranks = [str(n) for n in range(2, 11)] + list(JQKA)
suits = "spades diamonds clubs hearts".split()
def __init__(self):
self.cards=[Card(rank, suit) for suit in self.suits