Converting a string to an array?

Paul Rubin http
Fri Jan 13 11:45:05 CET 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