我正在尝试使用以下代码从没有反向重复的字符串列表中生成组合列表:
separator = "*";
VarList = ["y","lp","ep","rmp","cmp","cp","fp"]
newVarList = [];
currPosition = 0
for currVar in VarList:
currPosition +=1
nextPosition = 0
for nextVar in VarList:
nextPosition+=1
if currPosition != nextPosition:
currText = currVar + separator + nextVar
if currText not in newVarList:
newVarList.append(currText)
print len(newVarList)
print(' '.join(map(str, newVarList)))
我设法生成了组合,并在没有括号或引号的情况下列出了它们,但仍然存在反向重复。任何建议都将不胜感激。
确保curposition始终小于下一个位置:也许通过更改
if currPosition != nextPosition:
to
if currPosition < nextPosition:
应该删除重复项。