# analgous to a C hash table, so lookups are O(1) guids = { '********************000000012345': 'Boat', '12345***************************': 'Unicycle', 'BRUCE***************************': 'Batmobile', '****************************1337': 'Toyota Hilux', } def prefilter(string, placeholder = '*', min_length = 32): str_len = len(string) left = string right = string if str_len < min_length: diff = min_length - str_len left = placeholder * diff + left right = right + placeholder * diff return (left, right) def get_category(string, placeholder = '*', min_length = 32): str_len = len(string) if str_len < min_length: left,right = prefilter(string, placeholder, min_length) get_left = get_category(left, placeholder, min_length) if get_left: return get_left get_right = get_category(right, placeholder, min_length) if get_right: return get_right for i in range(32): right = string[:-i] + placeholder * i if right in guids: return guids[right] left = placeholder * i + string[i:] if left in guids: return guids[left] return False # right side print(get_category('BRUCE00')) print(get_category('12345')) # left side print(get_category('A*******************000000012345')) print(get_category('**WOT**********1337'))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question