diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2023-12-02 12:25:27 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2023-12-02 12:25:27 +0100 |
| commit | 3486e1463d03a356101506406c8fc9e2e99bcbe9 (patch) | |
| tree | cca1dd6890a4499eb1ed113995f8b1e49c877ecc /challenge-245/lubos-kolouch/python/ch-1.py | |
| parent | 2ac2c6b618af5515c64bbdd73482636ffe2f79aa (diff) | |
| download | perlweeklychallenge-club-3486e1463d03a356101506406c8fc9e2e99bcbe9.tar.gz perlweeklychallenge-club-3486e1463d03a356101506406c8fc9e2e99bcbe9.tar.bz2 perlweeklychallenge-club-3486e1463d03a356101506406c8fc9e2e99bcbe9.zip | |
feat(challenge-245/lubos-kolouch/perl,python,raku,blog): Challenge 245 LK Perl Python Raku blog
Diffstat (limited to 'challenge-245/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-245/lubos-kolouch/python/ch-1.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-245/lubos-kolouch/python/ch-1.py b/challenge-245/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..d960e4b918 --- /dev/null +++ b/challenge-245/lubos-kolouch/python/ch-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +import unittest +from typing import List, Tuple + + +def sort_language(langs: list[str], popularity: list[int]) -> list[str]: + combined = sorted(zip(langs, popularity), key=lambda x: x[1]) + return [lang for lang, _ in combined] + + +# Test Cases +class TestSortLanguage(unittest.TestCase): + def test_example_1(self): + self.assertEqual( + sort_language(["perl", "c", "python"], [2, 1, 3]), ["c", "perl", "python"] + ) + + def test_example_2(self): + self.assertEqual( + sort_language(["c++", "haskell", "java"], [1, 3, 2]), + ["c++", "java", "haskell"], + ) + + +if __name__ == "__main__": + unittest.main() |
