[Python-Dev] {}.popitem() (was Re: {}.first[key,value,item] ...)

Tim Peters tim.one@home.com
Tue, 12 Dec 2000 22:34:35 -0500


[Moshe Zadka]
> If we had an affine operation, instead of a linear one, we could have
> [0, 2**n). I won't repeat the proof here but changing
>
> def f(i):
>     i <<= 1
>     i^=1 # This is the line I added
>     if i >= 2**N:
>         i ^= MAGIC_CONSTANT_DEPENDING_ON_N
>     return i
>
> Makes you waltz all over [0, 2**n) if the original made you comple
> (0, 2**n).

[Tim]
> But, Moshe!  The proof would have been the most interesting part <wink>.

Turns out the proof would have been intensely interesting, as you can see by
running the attached with and without the new line commented out.

don't-ever-trust-a-theoretician<wink>-ly y'rs  - tim


N = 2
MAGIC_CONSTANT_DEPENDING_ON_N = 7

def f(i):
    i <<= 1
    # i^=1 # This is the line I added
    if i >= 2**N:
        i ^= MAGIC_CONSTANT_DEPENDING_ON_N
    return i

i = 1
for nothing in range(4):
    print i,
    i = f(i)
print i