This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, n): | |
self.n = n | |
self.left = None | |
self.right = None | |
class BinarySearchTree: | |
def __init__(self, node=None): | |
self.head = node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parent(i): | |
return (i + 1) / 2 - 1 | |
def left(i): | |
return (i + 1) * 2 - 1 | |
def right(i): | |
return ((i + 1) * 2) | |
def insert(heap, n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import requests | |
from lxml import html | |
rspca_base = 'https://www.rspca.org.uk' | |
def get_pet(name, ref): | |
base = rspca_base + '/findapet/details/-/Animal/{0}/ref/{1}/rehome/' | |
base = base.format(name, ref) | |
r = requests.get(base) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"title": "Sample Quiz", | |
"questions": [ | |
{ | |
"question": "Why did the chicken cross the road?", | |
"correct_answer": "C", | |
"answers": [ | |
{ | |
"option": "A", | |
"answer": "Because it wanted to." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
references = [] | |
with open('references.bib', 'r') as references_file: | |
references = re.findall('@\w*{(.*),', references_file.read()) | |
dupes = [x for x in references if references.count(x) > 1] | |
not_cited = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sign_factor(coords, matrix): | |
""" | |
Return the sign factor of the item in a matrix with | |
the coordinates specified by 'coords'. | |
""" | |
if (coords[0] % 2 == 0) != (coords[1] % 2 == 0): | |
return -1 | |
else: | |
return +1 |