File size: 338 Bytes
336f4a9
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
from ast import literal_eval


def dict_type(input_value):
    """Convert a string to a dictionary."""
    stripped_input = input_value.strip()
    if not stripped_input or stripped_input in ("{}", "''", '""'):
        return {}
    try:
        return literal_eval(stripped_input)
    except (SyntaxError, ValueError):
        return {}