0

The following list is generated from a function.

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]

Now I want to combine the numbers to generate new numbers and expect the new list to be :

 [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,  .. ...]

How can it be done in Python ??

1
  • Visit and read stackoverflow.com/help please. Provide more details and definitily show us what you have tried so far. Commented Jun 19, 2020 at 14:16

2 Answers 2

1

Use itertools.combinations:

>>> 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]
Sign up to request clarification or add additional context in comments.

Comments

0
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...]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.