How to slice a string in Python using a dictionary containing character positions?
<p>I have a dictionary containing the character positions of different fields in a string.  I'd like to use that information to slice the string.  I'm not really sure how to best explain this, but the example should make it clear:</p>

<p>input:</p>

<pre><code>mappings = {'name': (0,4), 'job': (4,11), 'color': (11, 15)}
data = "JohnChemistBlue"
</code></pre>

<p>desired output:</p>

<pre><code>{'name': 'John', 'job': 'Chemist', 'color': 'Blue'}
</code></pre>

<p>Please disregard the fact that jobs, colors and names obviously vary in character length.  I'm parsing fixed-length fields but simplified it here for illustrative purposes.</p>
