title: List of strings I want to group together if they contain a specific substring from a master list
body: <p>I have list of strings that I want to group together if they contain a specific substring from a master list.</p>
  <p>Example Input:</p>
  <pre><code>[&quot;Audi_G71Q3E5T7_Coolant&quot;, &quot;Volt_Battery_G9A2B4C6D8E&quot;, &quot;Speaker_BMW_G71Q3E5T7&quot;, &quot;Engine_Benz_G9A2B4C6D8E&quot;, &quot;Ford_G9A2B4C6D8E_Wheel&quot;, &quot;Toyota_Exhaust_G71Q3E5T7&quot;]
  </code></pre>
  <p>Master List:</p>
  <pre><code>[&quot;G71Q3E5T7&quot;, &quot;G9A2B4C6D8E&quot;]
  </code></pre>
  <p>Expected Output:</p>
  <pre><code>[[&quot;Audi_G71Q3E5T7_Coolant&quot;, &quot;Speaker_BMW_G71Q3E5T7&quot;, &quot;Toyota_Exhaust_G71Q3E5T7&quot;], [&quot;Volt_Battery_G9A2B4C6D8E&quot;, &quot;Engine_Benz_G9A2B4C6D8E&quot;, &quot;Ford_G9A2B4C6D8E_Wheel&quot;]]
  </code></pre>
  <p>I haven't found any example or solution online but am aware the <code>itertools.groupby()</code> function is useful in these scenarios, but am struggling to make it work.</p>