|
1 from configparser import ConfigParser |
|
2 profile = ConfigParser() |
|
3 |
|
4 def minmax(data): |
|
5 ''' |
|
6 From: http://code.activestate.com/recipes/577916-fast-minmax-function/ |
|
7 Computes the minimum and maximum values in one-pass using only |
|
8 1.5*len(data) comparisons |
|
9 ''' |
|
10 import itertools |
|
11 it = iter(data) |
|
12 try: |
|
13 lo = hi = next(it) |
|
14 except StopIteration: |
|
15 raise ValueError('minmax() arg is an empty sequence') |
|
16 for x, y in itertools.zip_longest(it, it, fillvalue = lo): |
|
17 if x > y: |
|
18 x, y = y, x |
|
19 lo = min(x, lo) |
|
20 hi = max(y, hi) |
|
21 return lo, hi |