Top-rated recipes tagged "mapping"http://code.activestate.com/recipes/tags/mapping/top/2012-10-24T00:44:30-07:00ActiveState Code Recipesxml to python dictionary and back (Python)
2012-10-24T00:44:30-07:00kris kvilekvalhttp://code.activestate.com/recipes/users/4178118/http://code.activestate.com/recipes/577722-xml-to-python-dictionary-and-back/
<p style="color: grey">
Python
recipe 577722
by <a href="/recipes/users/4178118/">kris kvilekval</a>
(<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/mapping/">mapping</a>, <a href="/recipes/tags/xml/">xml</a>).
Revision 2.
</p>
<p>Simple mapping of XML to python dictionary based on Perl XML::Simple</p>
An interval mapping data structure (Python)
2010-12-23T12:51:27-08:00Matteo Dell'Amicohttp://code.activestate.com/recipes/users/2433284/http://code.activestate.com/recipes/577515-an-interval-mapping-data-structure/
<p style="color: grey">
Python
recipe 577515
by <a href="/recipes/users/2433284/">Matteo Dell'Amico</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/interval/">interval</a>, <a href="/recipes/tags/mapping/">mapping</a>).
</p>
<p>This structure is a kind of dictionary which allows you to map data intervals to values. You can then query the structure for a given point, and it returns the value associated to the interval which contains the point. Boundary values don't need to be an integer.</p>
<p>In this version, the excellent <a href="http://pypi.python.org/pypi/blist/">blist</a> library by Daniel Stutzbach is used for efficiency. By using the collections.MutableMapping abstract base class, the whole signature of mappings is supported.</p>
Sorted dictionary (Python)
2010-01-20T17:11:59-08:00Jan Kaliszewskihttp://code.activestate.com/recipes/users/4172762/http://code.activestate.com/recipes/576998-sorted-dictionary/
<p style="color: grey">
Python
recipe 576998
by <a href="/recipes/users/4172762/">Jan Kaliszewski</a>
(<a href="/recipes/tags/collections/">collections</a>, <a href="/recipes/tags/dict/">dict</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/mapping/">mapping</a>, <a href="/recipes/tags/sorted/">sorted</a>, <a href="/recipes/tags/sorteddict/">sorteddict</a>).
Revision 29.
</p>
<p>A simple implementation of a dictionary which always (when applicable) returns keys, values, items (key-value pairs) sorted by keys (inserting/removing order doesn't matter and only keys are important; so please note that it is something different than OrderedDict in Python 3.1/2.7 or Django's SortedDict).</p>
Flipdict -- python dict that also maintains a one-to-one inverse mapping (Python)
2009-12-03T14:43:52-08:00Francis Carrhttp://code.activestate.com/recipes/users/4172444/http://code.activestate.com/recipes/576968-flipdict-python-dict-that-also-maintains-a-one-to-/
<p style="color: grey">
Python
recipe 576968
by <a href="/recipes/users/4172444/">Francis Carr</a>
(<a href="/recipes/tags/1_to_1/">1_to_1</a>, <a href="/recipes/tags/bijection/">bijection</a>, <a href="/recipes/tags/bijective/">bijective</a>, <a href="/recipes/tags/dict/">dict</a>, <a href="/recipes/tags/injection/">injection</a>, <a href="/recipes/tags/injective/">injective</a>, <a href="/recipes/tags/inverse/">inverse</a>, <a href="/recipes/tags/invert/">invert</a>, <a href="/recipes/tags/mapping/">mapping</a>, <a href="/recipes/tags/one_to_one/">one_to_one</a>).
Revision 6.
</p>
<p>A Flipdict is a python dict subclass that maintains a one-to-one inverse mapping. Each key maps to a unique value, and each value maps back to that same key. Each instance has a "flip" attribute to access the inverse mapping.</p>