Re: First script, please comment and advise

2006-03-10 Thread Just
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > >1. The fact that one function calls the other doesn't mean they're > >"logically nested".< > > In this situation they were logically nested, because the scramble_word > is a function needed by another one only, in Java the scramble_wor

Re: First script, please comment and advise

2006-03-10 Thread bruno at modulix
Pedro Graca wrote: > [EMAIL PROTECTED] 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. Yo

Re: First script, please comment and advise

2006-03-09 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: >> nested and hided inside a class. > > Hidden, sorry :-) > > >> Can a "sub-function" be called directly from outside the defining function? No, and each call to scramble_text defines a new function "scramble". Further, there is no way to unit test "scramble". --Scott D

Re: First script, please comment and advise

2006-03-09 Thread bearophileHUGS
> nested and hided inside a class. Hidden, sorry :-) >Can a "sub-function" be called directly from outside the defining function? I don't think you can access a nested function in a clean&nice way (and you can nest classes too, etc). With a little of Python magic maybe there is a way to do it..

Re: First script, please comment and advise

2006-03-09 Thread bearophileHUGS
This is different too, but maybe a little better than my last version: from random import shuffle from itertools import groupby def scramble_text(text): """Return the words in input text string scrambled, except for the first and last letter.""" def scramble(word): if len(word

Re: First script, please comment and advise

2006-03-09 Thread Pedro Graca
[EMAIL PROTECTED] 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 funct

Re: First script, please comment and advise

2006-03-09 Thread Pedro Graca
[EMAIL PROTECTED] wrote: > Just: >> [previous post, hand inserted] >>> def scramble_text(text): >>> def scramble_word(word): >> >> Btw. I find the use of a nested function here completely bogus: you >> don't need the surrounding scope. > > I don't agree, nested functions are useful to better st

Re: First script, please comment and advise

2006-03-09 Thread Pedro Graca
Just wrote: > In article <[EMAIL PROTECTED]>, > Pedro Graca <[EMAIL PROTECTED]> wrote: > [snip: very un-pythonic code] > > def curious(text): > """ Return the words in input text scrambled except for the > first and last letter. """ > new_text = "" > word = "" >

Re: First script, please comment and advise

2006-03-09 Thread Just
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > Just: > > > Btw. I find the use of a nested function here completely bogus: you > > don't need the surrounding scope. > > I don't agree, nested functions are useful to better structure your > program: to really nest things that are logi

Re: First script, please comment and advise

2006-03-09 Thread bearophileHUGS
Just: > Your text split behaves completely different from the original; I think > it was intentional that any puntuation wasn't affected. You are right, my versions is simpler but different and worse. Maybe it can be fixed a little... > Btw. I find the use of a nested function here completely b

Re: First script, please comment and advise

2006-03-09 Thread Just
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] 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): >

Re: First script, please comment and advise

2006-03-09 Thread bearophileHUGS
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]) shu

Re: First script, please comment and advise

2006-03-09 Thread Just
In article <[EMAIL PROTECTED]>, Pedro Graca <[EMAIL PROTECTED]> wrote: > I'm sure this isn't very pythonic; comments and advice appreciated > > > def curious(text): > """ Return the words in input text scrambled except for the first and > last letter. """ > new_text

First script, please comment and advise

2006-03-09 Thread Pedro Graca
I'm sure this isn't very pythonic; comments and advice appreciated def curious(text): """ Return the words in input text scrambled except for the first and last letter. """ new_text = "" word = "" for ch in text: if ch in "abcdefghijklmnopqrstuvwxy