Commutative combination of elements of two lists

前端 未结 6 517
感动是毒
感动是毒 2021-01-15 14:13

Just a style question: Is there a build-in method to get the combinations under the assertion of commutative property and excluding elements paired with itself?



        
6条回答
  •  野的像风
    2021-01-15 14:44

    Assuming a and b are identical.

    >>> import itertools
    >>> a = ["1", "2", "3"]
    >>> list(itertools.combinations(a,2))
    [('1', '2'), ('1', '3'), ('2', '3')]
    

提交回复
热议问题