sorry your code is even unclearer than that in the article where did you pull the from for example non experts of python won't know that the return format of bin a will have a b prefix note that python is used here as pseudocode so it's better to avoid assuming much knowledge of the python standard library the python code in the article suffers from two problems it's unclear what kind of value each variable holds the variables should either be renamed to something self descriptive or a comment should explain the role of each the code is slightly obscure because it tries to be smart about not recomputing an index expression now to explain the algorithm we don't need optimized code and an optimizing compiler which we'd use if efficiency is of any concern would spot this anyway so there isn't any reason to even slightly complicate the code even in production the code from the acm sian article by chan is much clearer here's transcribed and commented pseudocode def z order p q d returns true if p q according to z order in d dimensions p and q are supposed to be arrays of d coordinates i index of most significant dimension for j in range d use exclusive or to eliminate equal bits msb is less will see ones where the coordinates differ if msb is less p i q i p j q j i j return p i q i def msb is less l r returns true if the most significant bit of l is less than that of r return l r or l l r described as neat trick by chan note that the algorithm in the article has l r instead of l r this changes the result of msb is less but i suspect it does not change the result of z order