Constructs an dict representing a rectangle with keys x, y, w, h
771516
def xywh_from_points(points):
    
    xys = [[int(p) for p in pair.split(',')] for pair in points.split(' ')]
    minx = sys.maxsize
    miny = sys.maxsize
    maxx = 0
    maxy = 0
    for xy in xys:
        if xy[0] < minx:
            minx = xy[0]
        if xy[0] > maxx:
            maxx = xy[0]
        if xy[1] < miny:
            miny = xy[1]
        if xy[1] > maxy:
            maxy = xy[1]

    return {
        'x': minx,
        'y': miny,
        'w': maxx - minx,
        'h': maxy - miny,
    }
461100
def rectangle(self, x0, y0, x1, y1):
        """"""
        x0, y0, x1, y1 = self.rect_helper(x0, y0, x1, y1)
        self.polyline([[x0, y0], [x1, y0], [x1, y1], [x0, y1], [x0, y0]])
589117
def _encode_dict(d):
    """"""
    def enc(x):
        if isinstance(x, six.text_type):
            return x.encode(_ENCODING)
        else:
            return x

    return dict((enc(k), enc(v)) for k, v in six.iteritems(d))
860125
def _stringifyKeys(d):
    
    return dict((k.encode('ascii'), v)  for (k, v) in d.iteritems())
719226
def map_values(f, D):
    ''''''
    return { key:f(val) for key,val in D.iteritems() }
128178
def struct2dict(struct):
    """"""
    return {x: getattr(struct, x) for x in dict(struct._fields_).keys()}
1339999
def recarray2dict(recarray):
    """"""
    # TODO: subarrays
    result = {}
    for descr, value in zip(recarray.dtype.descr, recarray):
        name, dtype = descr[:2]
        if dtype[1] == 'S':
            value = bytes2str(stripnull(value))
        elif value.ndim < 2:
            value = value.tolist()
        result[name] = value
    return result
462718
def keys_in_dict(d, parent_key, keys):
    
    for key, value in d.iteritems():
        if isinstance(value, dict):
            keys_in_dict(value, key, keys)
        else:
            if parent_key:
                prefix = parent_key + "."
            else:
                prefix = ""

            keys.append(prefix + key)

    return keys
989464
def union_rectangles(R):
    
    if R == []:
        return 0
    X = []
    Y = []
    for j in range(len(R)):
        (x1, y1, x2, y2) = R[j]
        assert x1 <= x2 and y1 <= y2
        X.append(x1)
        X.append(x2)
        Y.append((y1, +1, j))    # generate events
        Y.append((y2, -1, j))
    X.sort()
    Y.sort()
    X2i = {X[i]: i for i in range(len(X))}
    L = [X[i + 1] - X[i] for i in range(len(X) - 1)]
    C = Cover_query(L)
    area = 0
    last = 0
    for (y, delta, j) in Y:
        area += (y - last) * C.cover()
        last = y
        (x1, y1, x2, y2) = R[j]
        i = X2i[x1]
        k = X2i[x2]
        C.change(i, k, delta)
    return area
238925
def dict_to_nx(graph, oriented=False):
    """"""
    nxg = nx.DiGraph() if oriented else nx.Graph()
    for node, succs in graph.items():
        for succ in succs:
            nxg.add_edge(node, succ)
    return nxg
1075214
def wc_dict2lha(wc, skip_redundant=True, skip_zero=True):
    """"""
    d = OrderedDict()
    for name, (block, i) in WC_dict_0f.items():
        if block not in d:
            d[block] = defaultdict(list)
        if wc[name] != 0:
            d[block]['values'].append([i, wc[name].real])
    for name in definitions.WC_keys_2f:
        reblock = 'WC'+name.upper()
        imblock = 'IMWC'+name.upper()
        if reblock not in d:
            d[reblock] = defaultdict(list)
        if imblock not in d:
            d[imblock] = defaultdict(list)
        for i in range(3):
            for j in range(3):
                if (i, j) in definitions.redundant_elements[name] and skip_redundant:
                    # skip redundant elements
                    continue
                if wc[name][i, j].real != 0 or not skip_zero:
                    d[reblock]['values'].append([i+1, j+1, float(wc[name][i, j].real)])
                if wc[name][i, j].imag != 0 or not skip_zero:
                    # omit Im parts that have to vanish by symmetry
                    if (i, j) not in definitions.vanishing_im_parts[name]:
                        d[imblock]['values'].append([i+1, j+1, float(wc[name][i, j].imag)])
    for name in definitions.WC_keys_4f:
        reblock = 'WC'+name.upper()
        imblock = 'IMWC'+name.upper()
        if reblock not in d:
            d[reblock] = defaultdict(list)
        if imblock not in d:
            d[imblock] = defaultdict(list)
        for i in range(3):
            for j in range(3):
                for k in range(3):
                    for l in range(3):
                        if (i, j, k, l) in definitions.redundant_elements[name] and skip_redundant:
                            # skip redundant elements
                            continue
                        if wc[name][i, j, k, l].real != 0 or not skip_zero:
                            d[reblock]['values'].append([i+1, j+1, k+1, l+1, float(wc[name][i, j, k, l].real)])
                        if wc[name][i, j, k, l].imag != 0 or not skip_zero:
                            # omit Im parts that have to vanish by symmetry
                            if (i, j, k, l) not in definitions.vanishing_im_parts[name]:
                                d[imblock]['values'].append([i+1, j+1, k+1, l+1, float(wc[name][i, j, k, l].imag)])
    # remove empty blocks
    empty = []
    for block in d:
        if d[block] == {}:
            empty.append(block)
    for block in empty:
        del d[block]
    return {'BLOCK': d}
46708
def map_axes(dim_vars, reverse_map=False):
    
    ret_val = defaultdict(list)
    axes = ['X', 'Y', 'Z', 'T']

    for k, v in dim_vars.items():
        axis = getattr(v, 'axis', '')
        if not axis:
            continue

        axis = axis.upper()
        if axis in axes:
            if reverse_map:
                ret_val[k].append(axis)
            else:
                ret_val[axis].append(k)

    return dict(ret_val)
1023698
def get_rectangle(self):
        
        rec = [self.pos[0], self.pos[1]]*2
        for age in self.nodes:
            for node in age:
                # Check max/min for x/y coords
                for i in range(2):
                    if rec[0+i] > node.pos[i]:
                        rec[0+i] = node.pos[i]
                    elif rec[2+i] < node.pos[i]:
                        rec[2+i] = node.pos[i]
        return tuple(rec)
1251743
function parse_rectangle(buf, pos) {
    if (!pos) {
        pos = 0;
    }

    return {
        x : buf[pos],
        y : buf[pos + 1],
        width : buf[pos + 2],
        height : buf[pos + 3]
    }
}
1364060
def dict_expand(o):
        
        r = {}
        for k, v in o.items():
            if isinstance(k, str):
                k = k.replace('$', '_')
            if "." in k:
                sub_r, keys = r, k.split('.')
                # create sub-dicts until last part of key
                for k2 in keys[:-1]:
                    sub_r[k2] = {}
                    sub_r = sub_r[k2]  # descend
                    # assign last part of key to value
                sub_r[keys[-1]] = v
            else:
                r[k] = v
        return r
545784
def grid_items(self):
        
        if list(self.keys()) == []:  return {}
        cols = self._max_cols
        return {(idx // cols, idx % cols): (key, item)
                for idx, (key, item) in enumerate(self.data.items())}
1274622
def key_dict( from_dict ):
	
	new_dict = {}
	old2new = {}
	new2old = {}
	for key in from_dict:
		k = normalizeUnicode(key,'identifier')
		if k != key:
			i = ''
			while new_dict.has_key("%s%s" % (k,i) ):
				if not i:
					i = 1
				else:
					i += 1
			k = "%s%s" % (k,i)
			old2new[key] = k
			new2old[k] = key
		new_dict[k] = from_dict[key]
	return (new_dict.keys(), new_dict, old2new, new2old)