Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 列表中数字的唯一组合_Python_List - Fatal编程技术网

Python 列表中数字的唯一组合

Python 列表中数字的唯一组合,python,list,Python,List,以下列表是从函数生成的 [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] 现在,我想结合这些数字生成新的数字,并期望新列表为: [23, 25, 27, 211, 213, 217, 219, 223, 229, 231, 32, 35, 37, 311, 313, 319, 323, 329, 331, 337, 52, 53, 57, 511, 513, 517, 519, 523, 529, 531, 537, 72, 73, 75, 711,

以下列表是从函数生成的

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
现在,我想结合这些数字生成新的数字,并期望新列表为:

 [23, 25, 27, 211, 213, 217, 219, 223, 229, 231, 32, 35, 37, 311, 313, 319, 323, 329, 331, 337, 52, 53, 57, 511, 513, 517, 519, 523, 529, 531, 537, 72, 73, 75, 711, 713, 717,  .. ...]

如何在Python中实现它???

使用
itertools.compositions

>>> import itertools
>>> [int(f"{a}{b}") for a, b in itertools.combinations([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37], 2)]
[23, 25, 27, 211, 213, 217, 219, 223, 229, 231, 237, 35, 37, 311, 313, 317, 319, 323, 329, 331, 337, 57, 511, 513, 517, 519, 523, 529, 531, 537, 711, 713, 717, 719, 723, 729, 731, 737, 1113, 1117, 1119, 1123, 1129, 1131, 1137, 1317, 1319, 1323, 1329, 1331, 1337, 1719, 1723, 1729, 1731, 1737, 1923, 1929, 1931, 1937, 2329, 2331, 2337, 2931, 2937, 3137]
请访问并阅读。提供更多详细信息,明确向我们展示您迄今为止的尝试。
x=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
new_list=[]
for i in x:
    for j in x:
        if j!=i:
           new_list.append(int(str(i)+str(j)))


#new_list should be [23, 25, 27, 211, 213, 217, 219, 223, 229, 231, 32...]