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
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)] |
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 timeit | |
from mytools import * | |
# | |
# | |
print( | |
'slide_each_simple (iterator)', | |
timeit.timeit( | |
stmt='slide_each_simple(range(1000), 3)', | |
globals=globals() |
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 timeit | |
from mytools import * | |
from mytools_other import * | |
import more_itertools_on_code as more_itertools | |
# | |
# | |
print( | |
'slide_each_simple (iterator)', | |
timeit.timeit( |
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
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: |
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
from pathlib import Path | |
_Path = type(Path()) | |
class Path(_Path): | |
def __iter__(self): | |
if self.is_dir(): | |
return self.iterdir() | |
raise TypeError |
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 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__': |
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 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 |
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
from pathlib import Path | |
import cv2 | |
import numpy as np | |
from tqdm import tqdm | |
def main(filename): | |
# 画像を読み込む |
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 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() | |
] |
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 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() |
OlderNewer