-1

I have Dict - test_dict = {'EU6XNAS' : '23TEST1'} print(test_dict.get('EU6XNAS')) is giving me o/p = 23TEST1 which is correct.

I wanted to get same O/P or Value if I search dictionary with first 3 char of String. something like test_dict.get('EU6') --> Currently It will give me None. Any other Method can i use in python?

Basically I wanted to have same o/p as "like" in sql rather than '=' exact match

  • Does this help https://stackoverflow.com/questions/18066603/fastest-way-to-search-python-dict-with-partial-keyword – A.T.B Jul 25 '23 at 16:47
  • You can use startswith method available in string. test_dict = {'EU6XNAS': '23TEST1'} for key in test_dict.keys(): if key.startswith('EU6'): print(test_dict[key]) Output: 23TEST1 – Dayananda D R Jul 28 '23 at 04:41

1 Answers1

0

You can use startswith method available in string.

test_dict = {'EU6XNAS': '23TEST1'}
for key in test_dict.keys():  
    if key.startswith('EU6'):
        print(test_dict[key])

Output:

23TEST1