shuffle string in python

后端 未结 4 2076
春和景丽
春和景丽 2020-11-27 17:59

I am looking for a function or short program that receives a string (up to 10 letters) and shuffles it.

4条回答
  •  抹茶落季
    2020-11-27 18:12

    you can use more_itertools.random_permutation

    from more_itertools import random_permutation
    
    s = 'ABCDEFGHIJ'
    ''.join(random_permutation(s))
    

    output:

    'DFJIEABGCH'
    

提交回复
热议问题