Use a xref of values to sub into tuple based on value - Python
<p>I have a list of xref values</p>

<pre><code>internal_customer = {'01':'11', '03':'33', '05':'55', '07':'77', '08':'88', '06':'66', '09':'22', '11':'18', '12':'19'}
</code></pre>

<p>that I would like to use to sub a value in a tuple:</p>

<pre><code>('03', 'S/N A1631703')
</code></pre>

<p>So my resulting tuple would be</p>

<pre><code>('33', 'S/N A1631703')
</code></pre>

<p>Can someone point me in the direction of the tools I could use to accomplish this?  </p>

<p>Unpack and access the dict using the first element, presuming you have an list of tuples:</p>

<pre><code>internal_customer = {'01':'11', '03':'33', '05':'55', '07':'77', '08':'88', '06':'66', '09':'22', '11':'18', '12':'19'}

lst = [('03', 'S/N A1631703'),('05', 'S/N A1631703')]

lst[:] = ((internal_customer[a], b) for a,b in t)    
print(t)
</code></pre>

<p>tuples are immutable so there is no notion of mutating, you have to create a new tuple comprising of the new value from the dict and the existing second element. The <code>lst[:]</code> syntax at least allows you to modify the original list. You can of course just reassign the name or create a completely new list if you want to maintain the original.</p>

python