diff options
| author | Steven <steven1170@zoho.eu> | 2025-05-19 17:23:37 +0100 |
|---|---|---|
| committer | Steven <steven1170@zoho.eu> | 2025-05-19 17:23:37 +0100 |
| commit | f785ffd9a3b62b8374bcf39ada3291d9f5d54247 (patch) | |
| tree | 3df471394f394fd386953618073b45b5e2e5672d | |
| parent | 032834a88dcad0af8ec93dbcfafc068e4a192864 (diff) | |
| download | perlweeklychallenge-club-f785ffd9a3b62b8374bcf39ada3291d9f5d54247.tar.gz perlweeklychallenge-club-f785ffd9a3b62b8374bcf39ada3291d9f5d54247.tar.bz2 perlweeklychallenge-club-f785ffd9a3b62b8374bcf39ada3291d9f5d54247.zip | |
small improvement
| -rw-r--r-- | challenge-322/steven-wilson/python/ch-2.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/challenge-322/steven-wilson/python/ch-2.py b/challenge-322/steven-wilson/python/ch-2.py index bd0b969657..6cc71ebada 100644 --- a/challenge-322/steven-wilson/python/ch-2.py +++ b/challenge-322/steven-wilson/python/ch-2.py @@ -13,13 +13,10 @@ def rank_array(integers): >>> rank_array([5, 1, 1, 4, 3]) (4, 1, 1, 3, 2) """ - integers_sorted = sorted(integers) + integers_sorted = sorted(set(integers)) rank_dict = {} - rank = 1 - for i in integers_sorted: - if i not in rank_dict: - rank_dict[i] = rank - rank += 1 + for n, i in enumerate(integers_sorted, start=1): + rank_dict[i] = n return tuple(rank_dict[i] for i in integers) |
