Reputation: 175
Following is a output from itertools.permutations function:
a = [(3, 1, 4, 1),
(3, 1, 1, 4),
(3, 4, 1, 1),
(3, 4, 1, 1),
(3, 1, 1, 4),
(3, 1, 4, 1),
(1, 3, 4, 1),
(1, 3, 1, 4),
(1, 4, 3, 1),
(1, 4, 1, 3),
(1, 1, 3, 4)...]
How can I get a list of numbers from the above data in the form:
[3141,3114,3411...]
Currently,I am only able to get it as:
[314131143411...]
Upvotes: 1
Views: 87
Reputation: 20669
You can try this.
def process_data(data):
return int(''.join(map(str,data)))
out=[process_data(i) for i in a]
# [3141, 3114, 3411, 3411, 3114, 3141, 1341, 1314, 1431, 1413, 1134,...]
Or
def process_data(data):
num=data[0]
for i in data[1:]:
num=num*10+i
return num
out=[process_data(i) for i in a]
# [3141, 3114, 3411, 3411, 3114, 3141, 1341, 1314, 1431, 1413, 1134,...]
Upvotes: 2