Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shuffle string in python

Tags:

python

string

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

like image 201
ariel Avatar asked Apr 19 '10 14:04

ariel


People also ask

Can I shuffle string in Python?

In Python, you can shuffle (= randomize) a list, string, and tuple with random.

What is shuffle method in Python?

Python Random shuffle() Method The shuffle() method takes a sequence, like a list, and reorganize the order of the items. Note: This method changes the original list, it does not return a new list.


1 Answers

>>> import random >>> s="abcdef123" >>> ''.join(random.sample(s,len(s))) '1f2bde3ac' 
like image 178
ghostdog74 Avatar answered Sep 27 '22 21:09

ghostdog74