From b098840586402fb3a99ce985aaae47d7d6973775 Mon Sep 17 00:00:00 2001 From: thematdev Date: Sun, 22 Jan 2023 12:31:32 +0300 Subject: [PATCH] Added compiler by name --- codeforces_scraper/languages.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/codeforces_scraper/languages.py b/codeforces_scraper/languages.py index cb897bd..d8163fc 100644 --- a/codeforces_scraper/languages.py +++ b/codeforces_scraper/languages.py @@ -22,11 +22,14 @@ ALL_LANGUAGE_COMPILERS = parse_obj_as( ) +def compiler_by_name(name: str) -> LanguageCompiler: + """Return compiler model by name""" + return next(filter(lambda comp: comp.name == name, ALL_LANGUAGE_COMPILERS)) + + def compiler_by_id(id: int) -> LanguageCompiler: """Return compiler model by id""" - for comp in ALL_LANGUAGE_COMPILERS: - if comp.id == id: - return comp + return next(filter(lambda comp: comp.id == id, ALL_LANGUAGE_COMPILERS)) def all_compilers_by_ext(extension: str) -> Iterable[LanguageCompiler]: