2

The program gets 5 random numbers(0-9).I generated permutations into a list. An example: numbers: 0,1,2,3,4 list = [(1,0,2,3,4),(1,0,2,4,3),...] and I would like to get: list = [10234,10243,...] And have to make an exception for 0, of course numbers can't start with 0. Only 5 digit numbers are accepted. So from the example can't get 1234, because 0 must be included everywhere except for the first.

import numpy as np
import itertools


m = np.random.randint(0,10,5)
m = list(m)
print(m)

x = set(itertools.permutations(m))
print(x)
num3ri
  • 822
  • 16
  • 20
  • Possible duplicate of [Join a list of items with different types as string in Python](https://stackoverflow.com/questions/3590165/join-a-list-of-items-with-different-types-as-string-in-python) – Sheldore May 11 '19 at 16:52

1 Answers1

2

I believe you can simply add:

list(map(int,(''.join(map(str,i)) for i in list(x) if i[0] != 0)))
# [44757, 44577, 47574, 74745, 74475,...
yatu
  • 86,083
  • 12
  • 84
  • 139