Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何创建具有独特元素的列表本身的笛卡尔积?
例如,lists = ['a', 'b', 'c'],我想创建[['a', 'b'], ['a','c'], ['b','c']].
lists = ['a', 'b', 'c']
[['a', 'b'], ['a','c'], ['b','c']]
from itertools import combinations lists = ['a', 'b', 'c'] print(list(map(list, combinations(lists,2))))