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
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
[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
> 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..
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
[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
[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
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 = ""
>
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
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
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):
>
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
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
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
14 matches
Mail list logo