Func any/generics

This commit is contained in:
Eden Kirin
2023-02-16 20:05:39 +01:00
parent 14ecd6b5b2
commit 0fcfcc0c16
2 changed files with 29 additions and 0 deletions

View 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()