-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
less restricted library type variables
- Loading branch information
fredokun
committed
Jun 13, 2023
1 parent
c5cb24a
commit 382067b
Showing
2 changed files
with
28 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
def groupes(f : Callable[[T], K], lst : List[T]) -> Dict[K, List[T]]: | ||
""" | ||
""" | ||
dico : Dict[K,List[T]] = dict() | ||
|
||
e : T | ||
for e in lst: | ||
k : K = f(e) | ||
if k in dico: | ||
dico[k].append(e) | ||
else: | ||
dico[k] = [e] | ||
|
||
return dico | ||
|
||
# Jeu de tests | ||
# TODO : str devrait être compatible avec Iterable[str] | ||
assert groupes(len, ["a", "as", "asd", "aa", "asdf", "qwer", "aa"]) \ | ||
== {1 : ["a"], 2 : ["as", "aa", "aa"], 3 : ["asd"], 4 : ["asdf", "qwer"]} |