Skip to content

Instantly share code, notes, and snippets.

from itertools import product, groupby
import operator
from UnionFind import UnionFind
def _renumber(id_list):
id_set = set(id_list)
replace_dict = dict(zip(
sorted(list(id_set)),
[i for i, _ in enumerate(id_set)]
@LouiS0616
LouiS0616 / measure_mytools.py
Last active January 26, 2018 12:44
my_itertools
import timeit
from mytools import *
#
#
print(
'slide_each_simple (iterator)',
timeit.timeit(
stmt='slide_each_simple(range(1000), 3)',
globals=globals()
import timeit
from mytools import *
from mytools_other import *
import more_itertools_on_code as more_itertools
#
#
print(
'slide_each_simple (iterator)',
timeit.timeit(
@LouiS0616
LouiS0616 / LICENSE
Created April 6, 2018 11:21
This license applies to all public gists https://gist.github.com/LouiS0616
MIT License
Copyright (c) 2018 Loui Sakaki
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
from pathlib import Path
_Path = type(Path())
class Path(_Path):
def __iter__(self):
if self.is_dir():
return self.iterdir()
raise TypeError
def printable_func(str_func=None):
if str_func is None:
str_func = lambda func: func.__name__
def inner(func):
return type(
func.__name__, (object, ),
{
**vars(func),
'__call__':
import math
def compute_lcm(a, b):
return (a * b) // math.gcd(a, b)
class MyFraction:
def __init__(self, numerator, denominator=1):
if denominator == 0:
raise ValueError
from pathlib import Path
import cv2
import numpy as np
from tqdm import tqdm
def main(filename):
# 画像を読み込む
class NamedZip:
def __init__(self, dct=None, **kwards):
if dct:
kwards = {**dct, **kwards}
self._names = kwards.keys()
self._iters = [
iter(val) for val in kwards.values()
]
import collections
import collections.abc
class PriorityDict(collections.abc.MutableMapping):
def __init__(self, default_priority_func):
self._default_priority_func = default_priority_func
self._inner_keys = set()