擅长:python、mysql、java
<p>您可以使用itertools中的<a href="https://docs.python.org/3.8/library/itertools.html#itertools.combinations" rel="nofollow noreferrer">combinations</a>函数来获得相同的结果。你知道吗</p>
<pre><code>from itertools import combinations
ad_material_name=['a', 'b', 'c']
for x, y in combinations(ad_material_name, r=2):
print([x, y])
</code></pre>
<p>或者,如果需要创建ad\u material\u name2变量并为其指定排列,可以执行以下操作:</p>
<pre><code>from itertools import combinations
ad_material_name=['a', 'b', 'c']
ad_material_name2 = [[*comb] for comb in combinations(ad_material_name, r=2)]
print(ad_material_name2)
# output
[['a', 'b'], ['a', 'c'], ['b', 'c']]
</code></pre>