rescale the values in a list between the values in newrange (a tuple with the new minimum and maximum)
167897
def rescale(inlist, newrange=(0, 1)):
    
    OldMax = max(inlist)
    OldMin = min(inlist)
    
    if OldMin == OldMax:
        raise RuntimeError('list contains of only one unique value')
    
    OldRange = OldMax - OldMin
    NewRange = newrange[1] - newrange[0]
    result = [(((float(x) - OldMin) * NewRange) / OldRange) + newrange[0] for x in inlist]
    return result
38109
def normalize_set(self, items, **kwargs):
        """"""
        values = set()
        for item in ensure_list(items):
            values.update(self.normalize(item, **kwargs))
        return list(values)
415187
function zrange(start, end, withscores) {
  var i
    , len = this._keys.length
    , list = [];
  if(start < 0) start = len + start;
  if(end < 0) end = len + end;
  if(start < 0) start = 0;
  if(end >= len) end = len - 1;
  i = start;
  for(;i <= end;i++) {
    list.push(this._keys[i].m);
    if(withscores) list.push(this._keys[i].v);
  }
  return list;
}
952669
def expand_slice(s, a, b, start=0, stop=None):
    ''''''
    n1 = max(s.start - a, start)
    n2 = s.stop + b
    if stop is not None:
        n2 = min(n2, stop)

    return slice(n1, n2, 1)
729450
def calculateRange(self, values):
        
        self.reset()
        self._values = list(set(values))
        self._values.sort(key=lambda x: values.index(x))
1133492
def between(self, min, max, limit=None, offset=None):
        
        if limit is not None and offset is None:
            offset = 0
        return self.zrangebyscore(min, max,
                start=offset, num=limit)
785643
def scale_images_0to1(slice1, slice2):
    """"""

    min_value = max(slice1.min(), slice2.min())
    max_value = max(slice1.max(), slice2.max())

    slice1 = (slice1 - min_value) / max_value
    slice2 = (slice2 - min_value) / max_value

    return slice1, slice2
742789
def min_values(args):
    
    return Interval(min(x.low for x in args), min(x.high for x in args))
944182
def range_by_score(self, min, max):
        """"""
        data = self.items()
        keys = [r[1] for r in data] 
        start = bisect.bisect_left(keys, min)
        end = bisect.bisect_right(keys, max, start)
        return self._as_set()[start:end]
915447
def set_range(self, min_val, max_val):
        
        if min_val > max_val:
            max_val, min_val = min_val, max_val
        self.values = (((self.values * 1.0 - self.values.min()) /
                        (self.values.max() - self.values.min()))
                       * (max_val - min_val) + min_val)
691047
private void eatRange(List list) {
        Token token0 = tokenizer.peekToken(0);
        Token token1 = tokenizer.peekToken(1);
        if (token0 == null) {// ∈
            return;
        }
        if (token1 != null && token1.getKind() == TokenKind.TO) {
            if (token0.getKind() == TokenKind.LITERAL_INT) {
                Token token2 = tokenizer.nextToken(2, TokenKind.LITERAL_INT);
                InnerRange range = new InnerRange(true, Integer.parseInt(token0.getData()),
                                                  Integer.parseInt(token2.getData()));
                list.add(range);
            } else if (token0.getKind() == TokenKind.LITERAL_LOWER_CHAR) {
                Token token2 = tokenizer.nextToken(2, TokenKind.LITERAL_LOWER_CHAR);
                InnerRange range = new InnerRange(false, token0.getData().charAt(0), token2.getData().charAt(0));
                list.add(range);
            } else if (token0.getKind() == TokenKind.LITERAL_UPPER_CHAR) {
                Token token2 = tokenizer.nextToken(2, TokenKind.LITERAL_UPPER_CHAR);
                InnerRange range = new InnerRange(false, token0.getData().charAt(0), token2.getData().charAt(0));
                list.add(range);
            } else {
                tokenizer.peekToken(0, TokenKind.LITERAL_INT, TokenKind.LITERAL_LOWER_CHAR,
                                    TokenKind.LITERAL_UPPER_CHAR);
            }
        } else if (token0.getKind() == TokenKind.LITERAL_INT) {
            list.add(Integer.parseInt(token0.getData()));
        } else if (token0.getKind() == TokenKind.LITERAL_DOUBLE) {
            list.add(Double.parseDouble(token0.getData()));
        } else if (token0.getKind() == TokenKind.LITERAL_STRING || token0.getKind() == TokenKind.LITERAL_LOWER_CHAR
                   || token0.getKind() == TokenKind.LITERAL_UPPER_CHAR) {
            list.add(token0.getData());
        } else {
            return;
        }
        Token token = tokenizer.nextToken();
        if (token != null && token.getKind() == TokenKind.COMMA) {
            tokenizer.nextToken();
            eatRange(list);
        }
    }
1211602
def expandParameters(*args):
    
    count = 1
    for arg in args:
        count = max(len(arg[0]), count)
    results = []
    for arg in args:
        results.append(expandValues(arg[0], count, args[1]))
    return tuple(results)
1093576
def compress_ranges_to_lists(self):
        '''
        
        '''
        clist = []
        for elem in self:
            if isinstance(elem, FixedListSubset):
                clist.append(elem.compress_ranges_to_lists())
            else:
                clist.append(elem)
        return clist
1335823
def normalize_to_unit_range(values):
    """"""
    if not isinstance(values, np.ndarray) or values.ndim != 1:
        raise ValueError('`values` must be a 1D NumPy array')

    if len(values) < 2:
        raise ValueError('`values` must contain at least two values')

    min_ = np.min(values)
    max_ = np.max(values)
    range_ = max_ - min_

    if range_ == 0:
        raise ValueError('range of `values` is 0 -- cannot normalize')

    return (values - min_) / range_
1175859
def downsample(values, target_length):
    
    assert target_length > 1
    values = list(values)
    if len(values) < target_length:
        return values
    ratio = float(len(values) - 1) / (target_length - 1)
    result = []
    for i in range(target_length):
        result.append(values[int(i * ratio)])
    return result
199727
def _scale_y_values(self, values, new_min, new_max, scale_old_from_zero=True):
        '''
        
        '''
        # Scale Y values - Create a scaled list of values to use for the visual graph
        scaled_values = []
        y_min_value = min(values)
        if scale_old_from_zero:
            y_min_value = 0
        y_max_value = max(values)
        new_min = 0
        OldRange = (y_max_value - y_min_value) or 1  # Prevents division by zero if all values are the same
        NewRange = (new_max - new_min)  # max_height is new_max
        for old_value in values:
            new_value = (((old_value - y_min_value) * NewRange) / OldRange) + new_min
            scaled_values.append(new_value)
        return scaled_values
910623
def PARAMLIMITS(self, value):
        """"""
        assert set(value.keys()) == set(self.PARAMLIMITS.keys()), "The \
                new parameter limits are not defined for the same set \
                of parameters as before."
        for param in value.keys():
            assert value[param][0] < value[param][1], "The new \
                    minimum value for {0}, {1}, is equal to or \
                    larger than the new maximum value, {2}"\
                    .format(param, value[param][0], value[param][1])
        self._PARAMLIMITS = value.copy()