First script, please comment and advise
Pedro Graca
hexkid at dodgeit.com
Thu Mar 9 15:17:10 EST 2006
bearophileHUGS at lycos.com wrote:
> My version is similar to Just one:
>
> from random import shuffle
>
> def scramble_text(text):
> """Return the words in input text string scrambled
> except for the first and last letter."""
> def scramble_word(word):
Nice. You can have functions inside functions.
However I think scramble_word() deserves being a callable function by
itself.
Can a "sub-function" be called directly from outside the defining
function?
> if len(word) < 4: return word
> core = list(word[1:-1])
> shuffle(core)
> return word[0] + "".join(core) + word[-1]
>
> return " ".join(map(scramble_word, text.split()))
>
> print scramble_text(scramble_text.__doc__)
Thank you for your version of the scrambler.
--
If you're posting through Google read <http://cfaj.freeshell.org/google>
More information about the Python-list
mailing list