Each line of the string holds a comma-separated key-value pair. Build a dictionary from it, converting each key with key_type and each value with value_type.
key_type and value_type are passed in as real types — str, int, float.
Example: 'a,1\nb,2' with str and int gives {'a': 1, 'b': 2}.
Implement this function:
def dict_from_string(string: str, key_type, value_type):
Write the function only — the arguments are read for you and the return value is printed automatically.
Input
'a,1\nb,2'
str
int
Output
{'a': 1, 'b': 2}