简体   繁体   中英

How to form a list of numbers from a list of Tuple of digits?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM