I am new to python and very new to using types. I have some function that returns a dictionary where the key
is a string and value
is a list of strings. I want to know what is the correct way to express this using types.
Sample output
{"lebron": ["king","goat","bron"], "jordan": ["clutch", "goat", "bulls"]}
Code
from typing import Any, Dict, List
def foo_bar() -> Dict[str, Any]:
my_map: Dict[str, Any] = {}
# some stuff happens
return my_map
def foo_bar() -> Dict[str, List[str]]:
my_map: Dict[str, List[str]] = {}
# some stuff happens
return my_map
I have posted two approaches one is more specific which is Dict[str, List[str]]
but i have never seen anyone use this anywhere so i am not sure if it is correct.