Mar-28-2023, 04:18 AM
Hi all, i am trying to do a partial search in a dict, everything i have tried needs the exact search term that will find the value if it contains the search but what i need is the opposite, enter a partial search item that will find the value as long as the key contains the search term.
but if i put a search_key of "M2MWA" it find nothing.
As a note the partial search could be anywhere with in the key.
est_dict = {"G1": 3, "GROUP1": 3, "G2": 5, "GROUP2": 5, "G3": 7, "GROUP3": 7, "LR": 9, "LISTED": 9, "QUALITY": 10, "OPEN": 12, "HCP": 12, "HANDICAP": 12, "100": 12, "96": 13, "95": 13, "94": 13, "93": 13, "92": 13, "91": 13, "C6": 13, "CL6": 13, "CLASS6": 13, "3MW": 15, "2MWA": 15, "WELTER": 16, "FLYING": 16, "90": 18, "89": 18, "88": 18, "87": 18, "86": 18, "85": 18, "1MW": 18, "ONE METRO WIN": 18, "0MW": 18, "NO METRO WIN": 18, "SET WEIGHTS": 20, "C5": 21, "CLASS5": 21, "84": 21, "83": 21, "82": 21, "81": 21, "80": 21, "79": 21, "78": 24, "77": 24, "76": 24, "75": 24, "74": 24, "73": 24, "72": 24, "71": 24, "C4": 25, "CLASS4": 25, "C3": 27, "CLASS3": 27, "70": 30, "69": 30, "68": 30, "67": 30, "66": 30, "65": 30, "64": 32, "63": 32, "62": 32, "61": 32, "60": 32, "59": 32, "C2": 34, "CLASS2": 34, "C1": 36, "CLASS1": 36, "58": 39, "57": 39, "56": 39, "55": 39, "54": 39, "53": 39, "52": 39, "51": 39, "50": 39, "MAIDEN": 42, "MDN": 42, "MSW": 42} search_key = "2MW" res = [val for key, val in test_dict.items() if search_key in key] print(str(res))this code would finds "2MWA": 15 and print 15
but if i put a search_key of "M2MWA" it find nothing.
As a note the partial search could be anywhere with in the key.