我有一份清单,就像这样,
a = ['dog','cat','mouse']
我想构建一个列表,它是所有列表元素的组合,看起来像,
ans = ['cat-dog', 'cat-mouse','dog-mouse']
这是我想出的,
a = ['dog','cat','mouse']
ans = []
for l in (a):
t= [sorted([l,x]) for x in a if x != l]
ans.extend([x[0]+'-'+x[1] for x in t])
print list(set(sorted(ans)))
有没有更简单,更蟒蛇的方式!