'Python convert List[str] to Dict[str, str] using ArgumentParser

I need to parse command line argument - convert List[str] to Dict[str, str]

['key1=value1', 'key2=value2'] -> {key1: value1, key2:value2}

I use the following code:

 parser.add_argument(
        '--model-config',
        nargs='+',
        type=model_config_str_to_dict        
    )

where model_config_str_to_dict(model_config: List[str]) is a function to convert list to dict. But instead of List[str] I get str for the model_config parameter.

My question is how can I parse --model-config parameter to convert it to dict?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source