Skip to content

Instantly share code, notes, and snippets.

View wilfreddesert's full-sized avatar

wilfreddesert

View GitHub Profile
from collections.abc import Sequence, Iterator
class RangeIterator(Iterator):
def __init__(self, range_object):
self.range_object = range_object
self.index = 0
def __next__(self):
try:
def chain(*args):
"""
>>> list(chain([[["test"]]]))
['t', 'e', 's', 't']
"""
for arg in args:
if isinstance(arg, str):
yield from arg
elif isinstance(arg, Iterable):
yield from chain(*arg)
from copy import deepcopy
def inverse_matrix(array):
augmented = deepcopy(array)
assert len(array) == len(array[0])
n = len(array)
for i in range(n):
for j in range(n):
if i == j:
class Ocean:
def __init__(self, init_state):
self.state = init_state
self.rows = len(self.state)
self.columns = len(self.state[0])
def __str__(self):
return str(self.state)
def gen_next_quantum(self):
class A:
_init = 0
def __init__(self, a, **kwargs):
A._init += 1
self.a = a
for key, value in kwargs.items():
setattr(self, key, value)
from numbers import Real
from typing import List
def merge(left: List[Real], right: List[Real]) -> List[Real]:
result = []
while left and right:
if left[0] >= right[0]:
result.append(right.pop(0))
else:
from math import log2
import pytest
from binary_search import binary_search
class CounterElNumber:
_lt_global_counter = 0
_eq_global_counter = 0
import pytest
import random
@pytest.fixture
def make_rnd_gen():
def _get_result(seed, mode):
# Hint: use pytest.fixture
if mode == 0:
return random.Random(seed).randint(-1000, 1000)
from lru_cache import LRUCache
from pytest import raises
def test_init():
lru = LRUCache(4)
assert lru.maxsize == 4
assert lru.cache == {}
import unittest
from math import sqrt
from vector import Vector
class TestVector(unittest.TestCase):
def test_repr(self):
v = Vector([1, 2, 3])
self.assertEqual(str(v), "Vector([1, 2, 3])")