Counting in Python Using a List


So before we begin, let me just tell you that this is a pretty useless thing to do.. But I was playing around with it while waiting for a C++ project to finish compiling, so why not!

The code (click here for the Gist):

magic = 0x616f-0x414f

numbers = [
    (magic/0x186A0),
    (magic/0x3E8/8),
    (magic/0x3E8/4),
    (magic/0o1534-7),
    (magic/0x3E8/2),
    (magic/0o2534-1),
    (magic/0o2544),
    (magic/0o075/19),
    (magic/0o064/19),
    (magic/0o1654)
]

i = c = numbers[0]

while True:
    print('%d%d' % (c, round(numbers[int(i)])))
    i += 1
    if i>len(numbers)-1:
        i = 0
        c += 1

If you ran it, it would look like this!

The numbers list in the code above is just an obfuscated way of writing 0..9.

The only real logic in this is the body of the while loop which prepends a zero each time it hits the end of the range.

This demonstrates the ability to count and not rely on the decimal system for example.