Python Itertools.Permutations()

前端 未结 4 1795
离开以前
离开以前 2020-12-09 07:47

Why does itertools.permutations() return a list of characters or digits for each permutation, instead of just returning a string?

For example:

>&g         


        
4条回答
  •  情话喂你
    2020-12-09 08:25

    Perumatation can be done for strings and list also, below is the example..

    x = [1,2,3]
    

    if you need to do permutation the above list

    print(list(itertools.permutations(x, 2)))
    
    # the above code will give the below..
    # [(1,2),(1,3),(2,1)(2,3),(3,1),(3,2)]
    

提交回复
热议问题