Converting a string to an array?

Paul Rubin http
Fri Jan 13 05:45:05 EST 2006


Tim Chase <python.list at tim.thechases.com> writes:
> The closest hack I could come up with was
> 
> 	import random
> 	s = "abcdefg"
> 	a = []
> 	a.extend(s)
> 	random.shuffle(a)
> 	s = "".join(a)

You could use

 	import random
 	s = list("abcdefg")
 	random.shuffle(s)
 	s = "".join(s)

which cuts down the clutter slightly.



More information about the Python-list mailing list