【发布时间】:2020-11-25 12:08:24
【问题描述】:
我有N number of List。在这里,我举两个例子。
List_1 = [5,6,7,8,9,10]
List_2 = [5,6,7,8,9,10]
我想从这 N 个列表中创建一个List of tuple。对于列表输出的两个元素应该是,
[(5,),(6,),(7,),(8,),(9,),(10,),(5,5,),(5,6)....(5,10),(6,5,),(6,6)....(6,10),(7,5,),(7,6)....(7,10)
.............(10,10)]
输出元素是1 to N number of elements pair using all combinations of list elements。
List_1 = [5,6,7,8,9,10]
List_2 = [5,6,7,8,9,10]
List_3 = [5,6,7,8,9,10]
对于 3 个列表元素的输出是,
[(5,),(6,),(7,),(8,),(9,),(10,),(5,5,),(5,6)....(5,10),(6,5,),(6,6)....(6,10),(7,5,),(7,6)....(7,10)
.............(10,10),(5,5,5)..(all combination of 1 ,2 & 3 elements items of three list)...(10,10,10)]
注意:所有列表都具有相同的值
【问题讨论】:
标签: python python-3.x list list-comprehension itertools