Re: mix up a string
Reinhold Birkenfeld wrote: > rbt wrote: > >>What's the best way to take a string such as 'dog' and mix it up? You >>know, like the word jumble in the papers? ODG. I thought something like >>mix = random.shuffle('dog') would do it, but it won't. Any tips? > > > py> def shuffled(s): > ... l = list(s) > ... random.shuffle(l) > ... return ''.join(l) > > > Reinhold Thanks guys, this works great. I forgot that shuffle needs a sequence... duh ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: mix up a string
rbt wrote: > What's the best way to take a string such as 'dog' and mix it up? You > know, like the word jumble in the papers? ODG. I thought something like > mix = random.shuffle('dog') would do it, but it won't. Any tips? py> def shuffled(s): ... l = list(s) ... random.shuffle(l) ... return ''.join(l) Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: mix up a string
rbt> mix = random.shuffle('dog') Try: lst = list('dog') random.shuffle(lst) print "".join(lst) Skip -- http://mail.python.org/mailman/listinfo/python-list
mix up a string
What's the best way to take a string such as 'dog' and mix it up? You know, like the word jumble in the papers? ODG. I thought something like mix = random.shuffle('dog') would do it, but it won't. Any tips? Thanks, rbt -- http://mail.python.org/mailman/listinfo/python-list