Binary Search

Other "Binary Search" solutions.
from typing import List

def find(search_list: List[int], value: int) -> int:
    if len(search_list) == 0:
        raise ValueError("value not in array")

    index = len(search_list) // 2

    middle_item = search_list[index]

    if middle_item > value:
        return find(search_list[0:index], value)
    elif middle_item < value:
        return index + 1 + find(search_list[index + 1:], value)

    return index

Binary Search Tree

Other "Binary Search Tree" solutions.
def push_node(tree_node, datum):
    if not tree_node:
        return TreeNode(datum)
    return tree_node.push(datum)


class TreeNode:
    def __init__(self, data, left=None, right=None):
        self.data = data
        self.left = left
        self.right = right

    def __str__(self):
        fmt = 'TreeNode(data={}, left={}, right={})'
        return fmt.format(self.data, self.left, self.right)

    def push(self, datum):
        if datum <= self.data:
            self.left = push_node(self.left, datum)
        else:
            self.right = push_node(self.right, datum)
        return self

    def dive(self):
        result = []
        if self.left:
            result += self.left.dive()
            result.append(self.data)
        else:
            result.append(self.data)

        if self.right:
            result += self.right.dive()
        return result


class BinarySearchTree:
    def __init__(self, tree_data):
        self.head = None
        for datum in tree_data:
            self.head = push_node(self.head, datum)

    def data(self):
        return self.head

    def sorted_data(self):
        return self.head.dive()

Hello World

Other "Hello World" solutions.
def hello():
    return "Hello, World!"

Pangram

Other "Pangram" solutions.
import string

def is_pangram(sentence: str):
    return set(sentence.lower()) >= set(string.ascii_lowercase)

Raindrops

Other "Raindrops" solutions.
def convert(number):
    result = ""
    if (number % 3) == 0:
        result += "Pling"
    if (number % 5) == 0:
        result += "Plang"
    if (number % 7) == 0:
        result += "Plong"
    if result == "":
        result = str(number)
    return result

Run Length Encoding

Other "Run Length Encoding" solutions.
from itertools import groupby


def decode(string):
    digits = ""
    acc = ""
    for c in string:
        if not c.isdigit():
            count = int(digits or 1)
            digits = ""
            acc += (c * count)
        else:
            digits += c
    return acc


def encode(string):
    def encode_group(k, g):
        count = len(list(g))
        if count == 1:
            return k
        return f"{count}{k}"

    return "".join([encode_group(k, g) for k, g in groupby(string)])

Two Fer

Other "Two Fer" solutions.
def two_fer(name="you"):
    return f"One for {name}, one for me."