title: Return large list of tuples with replaced dictionary value
body: <p>In python, I have a list of tuples (lot) with patient data, as shown below:</p>
  <pre><code>lot = [('490001', 'A-ARM1', '1', '2', &quot;a&quot;, &quot;b&quot;),
         ('490001', 'A-ARM2', '3', '4', &quot;c&quot;, &quot;d&quot;),
         ('490002', 'B-ARM3', '5', '6', &quot;e&quot;, &quot;f&quot;)]
  </code></pre>
  <p>In my real dataset, lot consists of 50-150 tuples (dependent on the patient). I loop through every second tuple element and wish to replace every 'A-' and 'B-' characters by a dictionary value, so the output will become:</p>
  <pre><code>[('490001', 'ZZARM1', '1', '2', 'a', 'b'), ('490001', 'ZZARM2', '3', '4', 'c', 'd'), ('490002', 'XXARM3', '5', '6', 'e', 'f')]
  </code></pre>
  <p>To satisfy this, I've written the code below. Here, I was wondering if there is a cleaner (shorter) way of writing this. For example, 'lot2'. The code should work optimally for a large list of tuples, as stated above. I'm eager to learn from you!</p>
  <pre><code>from more_itertools import grouper
  dict = {'A-': 'ZZ', 'B-': 'XX'}
  
  for el1, el2, *rest in lot:
      for i, j in grouper(el2, 2):
          if i + j in dict:
              lot2 = [ ( tpl[0], (tpl[1].replace(tpl[1][:2], dict[tpl[1][:2]])), tpl[2], tpl[3], tpl[4], tpl[5] ) for tpl in lot]
  print(lot2)
  </code></pre>