Python get all permutations of numbers

前端 未结 4 2020
臣服心动
臣服心动 2020-12-16 23:39

I\'m trying to display all possible permutations of a list of numbers, for example if I have 334 I want to get:

3 3 4
3 4 3
4 3 3

I need to

4条回答
  •  臣服心动
    2020-12-17 00:20

    >>> lst = [3, 3, 4]
    >>> import itertools
    >>> set(itertools.permutations(lst))
    {(3, 4, 3), (3, 3, 4), (4, 3, 3)}
    

提交回复
热议问题