Registry example
This commit is contained in:
33
generics_1_func.py
Normal file
33
generics_1_func.py
Normal file
@ -0,0 +1,33 @@
|
||||
from typing import Dict, TypeVar
|
||||
|
||||
|
||||
K = TypeVar("K")
|
||||
V = TypeVar("V")
|
||||
|
||||
|
||||
def get_item(values: Dict[K, V], key: K) -> V:
|
||||
return values[key]
|
||||
|
||||
|
||||
def main():
|
||||
str_keys: Dict[str, int] = {
|
||||
"prvi": 1,
|
||||
"drugi": 2,
|
||||
"treći": 3,
|
||||
}
|
||||
|
||||
a = get_item(str_keys, "drugi")
|
||||
print(a)
|
||||
|
||||
int_keys: Dict[int, str] = {
|
||||
1: "prvi",
|
||||
2: "drugi",
|
||||
3: "treći",
|
||||
}
|
||||
|
||||
a = get_item(int_keys, 3)
|
||||
print(a)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user