misc.py

Thu, 30 Jul 2020 21:52:31 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 30 Jul 2020 21:52:31 +0300
changeset 2
7378b802ddf8
parent 1
f9788970fa46
permissions
-rw-r--r--

destination processing

from configparser import ConfigParser
profile = ConfigParser()

def minmax(data):
	'''
	From: http://code.activestate.com/recipes/577916-fast-minmax-function/
	Computes the minimum and maximum values in one-pass using only
	1.5*len(data) comparisons
	'''
	import itertools
	it = iter(data)
	try:
		lo = hi = next(it)
	except StopIteration:
		raise ValueError('minmax() arg is an empty sequence')
	for x, y in itertools.zip_longest(it, it, fillvalue = lo):
		if x > y:
			x, y = y, x
		lo = min(x, lo)
		hi = max(y, hi)
	return lo, hi

mercurial