Popular recipes by Kai Mallea http://code.activestate.com/recipes/users/4174276/2010-06-25T20:44:04-07:00ActiveState Code RecipesScramble a string of words, preserving spaces (Python)
2010-06-25T20:44:04-07:00Kai Malleahttp://code.activestate.com/recipes/users/4174276/http://code.activestate.com/recipes/577275-scramble-a-string-of-words-preserving-spaces/
<p style="color: grey">
Python
recipe 577275
by <a href="/recipes/users/4174276/">Kai Mallea</a>
(<a href="/recipes/tags/scramble/">scramble</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/words/">words</a>).
</p>
<p>The following function will scramble a string, preserving spaces that separate the words, and return the result. I used this for a word game that scrambled words and phrases, which a player then attempted to descramble. For example, scrambling the following string: "teenage mutant ninja turtles" would return "etegnae tamtnu jnnai urtltes"</p>