First script, please comment and advise

Just just at xs4all.nl
Thu Mar 9 10:36:39 EST 2006


In article <1141917596.011498.311500 at p10g2000cwp.googlegroups.com>,
 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):
>         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__)

Your text split behaves completely different from the original; I think 
it was intentional that any puntuation wasn't affected.

Btw. I find the use of a nested function here completely bogus: you 
don't need the surrounding scope.

Just



More information about the Python-list mailing list