Help with Iteration
Aaron Brady
castironpi at gmail.com
Sun Oct 19 23:08:02 EDT 2008
On Oct 19, 12:27 pm, "Eric Wertman" <ewert... at gmail.com> wrote:
> >> Aaron Brady <cast...pigmail.com> wrote:
>
> >>> while 1:
> >>> calculate_stuff( )
> >>> if stuff < 0.00005:
> >>> break
>
> >> The thought police will come and get you.
>
> Based on Aaron's previous posting history, I suspect this was a joke.
Not necessarily, (technically...) if you mean that those 4 lines would
never be consistent with my other stuff, see below. I didn't intend
to mock the OP at all. But you're right, it definitely looked
oversimplified.
'calculate_stuff' could have been defined local to the function:
def f():
stuff= [1]
def calculate_stuff( ):
stuff.append( stuff[-1]* 2 )
calculate_stuff( )
Then the test 'if some_comparison( stuff )' still makes sense and
doesn't require a global variable.
For the 'stuff < 0.00005' test in particular to make sense, 'stuff'
could be an instance of an object with '__lt__' defined.
Since Python doesn't define an 'until' statement in addition to
'while', the question could have been about control flow.
More information about the Python-list
mailing list