基本上,我需要得到一个列表的几个排列方式。所以,我使用的方法是随机地打乱列表字符串以获取排列,并将其添加到一个列表中,同时添加时检查是否存在相同的排列。我无法实现检查。这是我编写的代码。
list = [x for x in range(0,max)]
totalperm = 10
perms = []
while(len(perms) <> totalperm):
random.shuffle(list)
if list not in perms:
perms.append(list)
请告诉我这里缺少了什么。
random.shuffle(listnew)
if listnew not in perms: perms.append(listnew)
print perms del listnew '但这也不起作用。 - AKG
set
的示例,这更符合Python的风格。 - Rob Wouters