aboutsummaryrefslogtreecommitdiff
path: root/challenge-245
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-11-29 15:29:54 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-11-29 15:29:54 +0000
commitd6ff45101a313dd84d56e359b2e4a413178ebfac (patch)
tree99fc7634b6316406f3f3a4e9832803ce3f3cf49e /challenge-245
parent313f3f870d8ba92f3a5f7b8e456e6487c380f9d9 (diff)
parentc087e0520ff80805cb9fcf98eb34c51056192aaa (diff)
downloadperlweeklychallenge-club-d6ff45101a313dd84d56e359b2e4a413178ebfac.tar.gz
perlweeklychallenge-club-d6ff45101a313dd84d56e359b2e4a413178ebfac.tar.bz2
perlweeklychallenge-club-d6ff45101a313dd84d56e359b2e4a413178ebfac.zip
Merge branch 'oWnOIzRi-week245'
Diffstat (limited to 'challenge-245')
-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__":