Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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_Python 3.x_List_Data Structures_Tuples - Fatal编程技术网

Python 如何从数字元组列表中形成数字列表?

Python 如何从数字元组列表中形成数字列表?,python,python-3.x,list,data-structures,tuples,Python,Python 3.x,List,Data Structures,Tuples,以下是itertools.permutations函数的输出: 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

以下是itertools.permutations函数的输出:

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)...]
我如何从上述数据中获得以下表格中的数字列表:

[3141,3114,3411...]
目前,我只能通过以下方式获得:

[314131143411...]
你可以试试这个

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


你尝试过什么?你面临什么问题?这是否回答了你的问题@buran事实上,先生,我得到了一个数字列表,从中我必须选择可以被3整除的最大数字。例如:[3,1,4,1]应该输出为4311因为问题陈述太大,我只想提到我需要帮助的部分。如果愿意,我可以编辑问题。
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,...]