aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-11-29 15:28:29 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-11-29 15:28:29 +0000
commitc087e0520ff80805cb9fcf98eb34c51056192aaa (patch)
tree99fc7634b6316406f3f3a4e9832803ce3f3cf49e
parent313f3f870d8ba92f3a5f7b8e456e6487c380f9d9 (diff)
parent147434fb329c314a30866a960e2637949129d28d (diff)
downloadperlweeklychallenge-club-c087e0520ff80805cb9fcf98eb34c51056192aaa.tar.gz
perlweeklychallenge-club-c087e0520ff80805cb9fcf98eb34c51056192aaa.tar.bz2
perlweeklychallenge-club-c087e0520ff80805cb9fcf98eb34c51056192aaa.zip
Merge branch 'week245' of https://github.com/oWnOIzRi/perlweeklychallenge-club into oWnOIzRi-week245
-rw-r--r--challenge-245/steven-wilson/python/ch-1.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/challenge-245/steven-wilson/python/ch-1.py b/challenge-245/steven-wilson/python/ch-1.py
index 9017f8cfa6..6f6a56eaed 100644
--- a/challenge-245/steven-wilson/python/ch-1.py
+++ b/challenge-245/steven-wilson/python/ch-1.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
-def sort_language(lang, popularity):
+def sort_language(language, popularity):
''' Given 2 arrays: languages and popularity. Sorts the language
based on popularity.
>>> sort_language(('perl', 'c', 'python'), (2, 1, 3))
@@ -9,7 +9,10 @@ def sort_language(lang, popularity):
>>> sort_language(('c++', 'haskell', 'java'), (1, 3, 2))
('c++', 'java', 'haskell')
'''
- return tuple(sorted(lang, key=lambda l: popularity[lang.index(l)]))
+ if len(language) != len(popularity):
+ raise ValueError("Lengths of 'language' and 'popularity' must be the same.")
+ language_popularity = dict(zip(language, popularity))
+ return tuple(sorted(language, key=lambda l: language_popularity.get(l)))
if __name__ == "__main__":