permutations with unique values

前端 未结 19 1799
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 01:53

itertools.permutations generates where its elements are treated as unique based on their position, not on their value. So basically I want to avoid duplicates like this:

19条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 02:38

    You could try using set:

    >>> list(itertools.permutations(set([1,1,2,2])))
    [(1, 2), (2, 1)]
    

    The call to set removed duplicates

提交回复
热议问题