很抱歉我无法以优雅的方式撰写问题。我希望进一步的文字足以理解我的问题。
我有一组包含一到五个成员的列表。我想从每个列表中创建图表。
我的数据:
data = [
['07F', '05F', '10F', '06F'],
['05T', '05F', '02T'],
['03T', '03F']
]
我希望每个列表都会产生所有可能的列表对:
['07F', '05F', '10F', '06F'] should become ----------->
['07F',05F']
['07F',10F']
['07F',06F']
['05F',10F']
['05F',06F']
['10F',06F']
所有下一个列表都一样。
我所理解的是,我必须遍历列表,然后......?
答案 0 :(得分:4)
import itertools
from pprint import pprint
data = [
['07F', '05F', '10F', '06F'],
['05T', '05F', '02T'],
['03T', '03F']
]
# Create a list of the lists of pair-wise combinations
data = [list(itertools.combinations(x,2)) for x in data]
pprint(data)
答案 1 :(得分:2)
import itertools
print [a for a in itertools.combinations(data,2)]