└── README.md /README.md: -------------------------------------------------------------------------------- 1 | def difference_by(a, b, fn): 2 | b = set(map(fn, b)) 3 | return [item for item in a if fn(item) not in b] 4 | 5 | from math import floor 6 | difference_by([2.1, 1.2], [2.3, 3.4],floor) # [1.2] 7 | difference_by([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], lambda v : v['x']) # [ { x: 2 } ] 8 | from functools import reduce 9 | 10 | 11 | def spread(arg): 12 | ret = [] 13 | for i in arg: 14 | if isinstance(i, list): 15 | ret.extend(i) 16 | else: 17 | ret.append(i) 18 | return ret 19 | 20 | 21 | def lcm(*args): 22 | numbers = [] 23 | 24 | 25 | 26 | 27 | 28 | 29 | Number 30 | Enter the number you want the square root of. 31 | 16 32 | 33 | 34 | 35 | def host_is_pingable(ip): 36 | return os.system(f"ping -c 1 {ip}") 37 | 38 | def wait_until(condition, description, timeout=300, period=5, *args, **kwargs): 39 | final_time = time.time() + timeout 40 | while time.time() < final_time: 41 | output = condition(*args, **kwargs) 42 | if output: 43 | return output 44 | time.sleep(period) 45 | raise TimeoutError(f'Timed out waiting for condition: [{description}]') 46 | /// 47 | // 48 | --------------------------------------------------------------------------------