New assignmens ...

Chris Angelico rosuav at gmail.com
Wed Oct 27 14:42:45 EDT 2021


On Thu, Oct 28, 2021 at 4:34 AM Christman, Roger Graydon <dvl at psu.edu> wrote:
> Do you put special code in next_couple() to recognize that the provided arguments
> are actually the first couple so it can return those unmodified, but then require its
> own mental note not to give you an infinite loop forever returning that first couple?
>
> Do you have to define a special case such as (a,b) = (0,0) or (None,None) to tell
> next_couple that you really want the first one?   That seems a little counter-intuitive
> to have something named "next" need a special input to mean "first",

In some cases, there is a very real special startup value (a seed).
For instance, if we're calculating something relating to the
Mandelbrot set:

# The point we're working with
c = (0.25 + 0.125j)
# Always start here
z = (0 + 0j) # or just 0
while abs(z := z*z+c) < 2:
    ...


Though in this case, you don't look for a next_couple, you look for a
single next value, and the other value is constant.

But it all depends on the exact process being done, which is why I've
been asking for real examples.

ChrisA


More information about the Python-list mailing list