This is just superstition, and sadly for a while this is what is this forum topic is about. This and bad python codes.
I guess you haven't seen COBRAS's.
What's wrong with having code that explodes in complexity? Most people here have zero clues about algorithms, and they complicate things terribly instead of simplifying them. Mostly because things can't really be simplified, so desperate solutions appear.
Here's a quick way to compute the prefix size, in number of bits, without having to run a loop across string searching for hex non-sense:
h160_c = int.from_bytes(h160). # this is a CONSTANT integer
# Magical XOR. Read it up on Wikipedia.
prefix_len = 160 - (h_160c ^ int.from_bytes(h160_d)).bit_length()
This is what people did, well, IDK, before AI made us all experts in bad coding. It's called using a brain.