Spaces:
Runtime error
Runtime error
Create utils.py
Browse files
utils.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from functools import cache
|
2 |
+
|
3 |
+
|
4 |
+
def convert_keys_to_lowercase(input_dict):
|
5 |
+
return {key.lower(): value for key, value in input_dict.items()}
|
6 |
+
|
7 |
+
def match_in_keys(dictionary, search_string):
|
8 |
+
lowercase_dict = convert_keys_to_lowercase(dictionary)
|
9 |
+
if search_string.lower() in list(lowercase_dict.keys()):
|
10 |
+
return lowercase_dict.get(search_string.lower())
|
11 |
+
for l_key in lowercase_dict.keys():
|
12 |
+
if l_key.startswith(search_string.lower()):
|
13 |
+
return lowercase_dict.get(l_key)
|
14 |
+
|
15 |
+
def match_in_values(dictionary, search_string):
|
16 |
+
lowercase_dict = convert_keys_to_lowercase(dictionary)
|
17 |
+
if search_string.lower() in list(lowercase_dict.values()):
|
18 |
+
return search_string
|