【发布时间】:2014-05-17 20:17:05
【问题描述】:
我正在尝试从字符串生成长度为 2 的唯一排列,但我得到了重复的值。我究竟做错了什么? 代码如下:
a = 'abba'
from itertools import permutations
x = []
x = [y for y in list(permutations(a,2)) if y not in x]
'''
output was this:
[('a', 'b'), ('a', 'b'), ('a', 'a'), ('b', 'a'), ('b', 'b'), ('b', 'a'), ('b', 'a'), ('b', 'b'),('b', 'a'), ('a', 'a'), ('a', 'b'), ('a', 'b')]
'''
【问题讨论】:
标签: python-3.x