Add files

Signed-off-by: András Schmelczer <andras@schmelczer.dev>
This commit is contained in:
Andras Schmelczer 2022-04-02 13:47:33 +02:00
commit d79a75d352
102 changed files with 24317 additions and 0 deletions

16
good_ai/src/sus/unique.py Normal file
View file

@ -0,0 +1,16 @@
from typing import Any, Callable, Iterable, List
def unique(
values: Iterable[Any], *, key: Callable[[Any], Any] = lambda v: v
) -> List[Any]:
"""Only keep first occurrences and maintian order"""
key_values = {}
for v in values:
k = key(v)
if k not in key_values:
# dicts maintin insertion order: https://mail.python.org/pipermail/python-dev/2017-December/151283.html
key_values[k] = v
return list(key_values.values())