Valid memory address in Python
In this code:


if len(addr) &lt;= 8:
    val = int(addr, 16)
    if val &lt;= (1 &lt;&lt; 16):  # val &lt;= 0xffff (ie: first 64k)
        return True
elif addr.startswith('ffffffff'):
    addr = addr[8:]  # 8 == len('ffffffff')
    val = int(addr, 16)
    if val &gt;= ((1 &lt;&lt; 32) - (1 &lt;&lt; 16)):  # val &gt;= 0xffffffffffff0000 (ie: last 64k)
        return True



You can replace the inner if statements with return statements:

if len(addr) &lt;= 8:
    val = int(addr, 16)
    return val &lt;= (1 &lt;&lt; 16)  # val &lt;= 0xffff (ie: first 64k)
elif addr.startswith('ffffffff'):
    addr = addr[8:]  # 8 == len('ffffffff')
    val = int(addr, 16)
    return val &gt;= ((1 &lt;&lt; 32) - (1 &lt;&lt; 16))  # val &gt;= 0xffffffffffff0000 (ie: last 64k)


This is possible because if these conditions are false,
the execution will reach the return False at the end of the function.
The reason to rewrite this way is so that the reader doesn't have to follow the execution path until the end of the function,
he can know on these lines that no further statements will be executed,
the return value is already decided at these points.



Some of the comments are incorrect and misleading:


if val &lt;= (1 &lt;&lt; 16):  # val &lt;= 0xffff (ie: first 64k)

if val &gt;= ((1 &lt;&lt; 32) - (1 &lt;&lt; 16)):  # val &gt;= 0xffffffffffff0000 (ie: last 64k)



1 &lt;&lt; 16 is 0x10000, not 0xffff.

(1 &lt;&lt; 32) - (1 &lt;&lt; 16) is 0xffff0000, not 0xffffffffffff0000.



Following the naming conventions of Python,
the function isweird should be named is_weird instead.