回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在用Python构建<strike>字典</strike>列表,目的是逐个遍历每个字典并连接所有不同的组合。在<strike>字典中,每个“产品”有三个不同的组成部分:</p>
<p>1)字母,例如<code>'A'</code>(产品代码的第一部分,对每个产品条目都是唯一的)。假设范围是:</p>
<pre><code>['A', 'B', 'C']
</code></pre>
<p>2)字母和数字,例如<code>'S2'</code>(第二部分有几个变体…可能是<code>'D3'</code>或<code>'E5'</code>)</p>
<p>3)一个句点(<code>'.'</code>)和一个字母,例如<code>'.X'</code>(第三部分,每个产品条目都是唯一的)。假设范围是:</p>
<pre><code>['.X', '.Y', '.Z']
</code></pre>
<p>由于上面列出的第二部分有最多的变化,我的初始假设是将第一部分和第三部分一起构建<strike>dicts</strike>列表,以减少不同列表的数量<strike>dicts</strike>,因为它们是唯一成对的,例如<code>A.Z'</code>…但是,我仍然需要拆分每个条目,然后通过一些“连接”命令在它们之间插入第二部分。所以,问题是:如果我有另一个包含第二部分所有变体的<strike>dict</strike>列表,我应该使用什么函数来构建产品的所有变体?你知道吗</p>
<p>示例的总组合:</p>
<pre><code>ListOne = ['A', 'B', 'C']
ListTwo = ['D3', 'D4', 'D5', 'E3', 'E4', 'E5']
ListThr = ['.X', '.Y', '.Z']
</code></pre>
<p>我需要创建新的<strike>dicts</strike>列表作为所有三个<strike>dicts</strike>列表的串联,例如<code>'AD3.X'</code>,但是<code>ListOne</code>和<code>ListThr</code>没有变体,它总是<code>'A'</code>与<code>'.X'</code>或<code>'B'</code>匹配,并且<code>'C'</code>与<code>'.Y'</code>匹配…<code>ListTwo</code>在<code>ListOne</code>和<code>ListThr</code>产品之间串联的产品将需要迭代,因此所有可能的组合都作为一个新的<strike>dict</strike>列表输出,例如</p>
<pre><code>ListOneNew = ['AD3.X', 'AD4.X', AD5.X', 'AE3.X', 'AE4.X', 'AE5.X']
ListTwoNew = ['BD3.Y', 'BD4.Y', 'BD5.Y', <and so on...>]
</code></pre>
<p>为了简单起见,脚本应该有<code>ListOne</code>和<code>ListThr</code>的合并版本吗</p>
<pre><code>List = ['A.X', 'B.X', 'C.Z']
</code></pre>
<p>然后用<code>ListTwo</code>产品拆分并连接,或者只使用三个<code>List</code>产品并从那里连接?你知道吗</p>