From e3042c4327200990cfc2d05943479f2aa713aa80 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 23 Jul 2024 16:19:02 +0100 Subject: add solutions week 279 in python --- challenge-279/steven-wilson/python/ch-1.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 challenge-279/steven-wilson/python/ch-1.py (limited to 'challenge-279/steven-wilson/python/ch-1.py') diff --git a/challenge-279/steven-wilson/python/ch-1.py b/challenge-279/steven-wilson/python/ch-1.py new file mode 100644 index 0000000000..755c3b4141 --- /dev/null +++ b/challenge-279/steven-wilson/python/ch-1.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + + +def sort_letters(letters, weights): + """ Given two arrays, sort the given array letters based on the weights. + >>> sort_letters(('R', 'E', 'P', 'L'), (3, 2, 1, 4)) + 'PERL' + >>> sort_letters(('A', 'U', 'R', 'K'), (2, 4, 1, 3)) + 'RAKU' + >>> sort_letters(('O', 'H', 'Y', 'N', 'P', 'T'), (5, 4, 2, 6, 1, 3)) + 'PYTHON' + """ + letters_sorted = (l for _, l in sorted(zip(weights, letters))) + return "".join(letters_sorted) + + +if __name__ == "__main__": + import doctest + + doctest.testmod(verbose=True) -- cgit