回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一个列表:</p>
<pre><code>result = [['GELATIN', '76.0 mg', '40 %', 'Gelatin to 100.000 g Table 7 Capsule Quantity per unit flavouring dose Quantity per unit dose Components Nominal mass of capsule 76.0 mg In the cap (40 %) 30.4 mg flavouring agent corresponds to 1 '],
['GELATIN', '45.6 mg', '14.5 %', 'Gelatin including water of a certain percentage'],
['INK', '76.0 mg', '40 %', 'ink is used as diluent far as this is necessary for the markets. Table 4 Atenolol granules Components mg/capsule Granules Active ingredients Atenolol 50.00]]
</code></pre>
<p>以及字符串列表:</p>
<pre><code>agent = ['Flavouring Agent', 'Anti-Tacking Agent', 'Preservative', 'Colouring Agent', 'Ph Adjusting Agent', 'Plasticizer', 'Diluent']
</code></pre>
<p>对于<code>result</code>中的每个子列表,我想从<code>agent</code>列表中搜索子列表中任意位置的元素。如果存在这样的元素,则将其作为新元素添加到子列表的开头。你知道吗</p>
<p>预期产量:</p>
<pre><code>new_result = [['Flavouring Agent', 'GELATIN', '76.0 mg', '40 %', 'Gelatin to 100.000 g Table 7 Capsule Quantity per unit flavouring dose Quantity per unit dose Components Nominal mass of capsule 76.0 mg In the cap (40 %) 30.4 mg flavouring agent corresponds to 1 '],
['GELATIN', '45.6 mg', '14.5 %', 'Gelatin including water of a certain percentage'],
['Diluent', 'INK', '76.0 mg', '40 %', 'ink is used as diluent far as this is necessary for the markets. Table 4 Atenolol granules Components mg/capsule Granules Active ingredients Atenolol 50.00]]
</code></pre>
<p>这是因为<code>'Flavouring Agent'</code>出现在第一个子列表的最后一个元素中;<code>'Diluent'</code>出现在最后一个子列表的最后一个元素中。你知道吗</p>
<p>迄今为止的努力:</p>
<pre><code>newl=[]
for jj in agent:
for e in result:
for ll in e:
if jj in ll:
#print(jj,ll)
newl.append([jj,ll])
break
</code></pre>