How to pass out the result from iterated function

JD Jiandong.Ge at gmail.com
Thu Dec 11 15:55:04 CET 2008


On Dec 10, 2:25 pm, eric <e... at ericaro.net> wrote:
> On Dec 10, 9:16 pm, JD <Jiandong... at gmail.com> wrote:
>
>
>
> > I got a iterated function like this:
>
> > def iterSomething(list):
> >     has_something = False
> >     for cell in list:
> >         if something in cell:
> >             has_something = True
> >             output = something
> >    if has_something:
> >        iterSomething(output)
> >    else:
> >        final_out = outupt
>
> > The problem is how can I read this final_out outside of the function.
> > I tried the global statement, it seems not work. Any idea?
>
> > JD
Thanks,

I tried to return the last result. It's not working. Your code works,
thanks



> why don't you just return it ?
>
> def iterSomething(list):
>     has_something = False
>     for cell in list:
>         if something in cell:
>             has_something = True
>             output = something
>    if has_something:
>        return iterSomething(output)
>    else:
>        return output
>
> ?




More information about the Python-list mailing list