diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-05-20 20:58:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-20 20:58:42 +0100 |
| commit | 7d4b96fc49531e5b0a6e2b862fa3bc9aa05ecf8b (patch) | |
| tree | ca5c9b737e907ca00f12c0f35c2372396025042b | |
| parent | bd86fe7afe96e316069d6fb53f67cefaa08d18e4 (diff) | |
| parent | a65673de75201e1ca7da5530b037fcf40dbee37b (diff) | |
| download | perlweeklychallenge-club-7d4b96fc49531e5b0a6e2b862fa3bc9aa05ecf8b.tar.gz perlweeklychallenge-club-7d4b96fc49531e5b0a6e2b862fa3bc9aa05ecf8b.tar.bz2 perlweeklychallenge-club-7d4b96fc49531e5b0a6e2b862fa3bc9aa05ecf8b.zip | |
Merge pull request #12056 from ysth/challenge-322-ysth
challenge 322 better python solution for challenge 2 by ysth
| -rw-r--r-- | challenge-322/ysth/python/ch-2.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/challenge-322/ysth/python/ch-2.py b/challenge-322/ysth/python/ch-2.py index 75301f87a5..058872ecca 100644 --- a/challenge-322/ysth/python/ch-2.py +++ b/challenge-322/ysth/python/ch-2.py @@ -1,17 +1,19 @@ import sys +import operator integers = [int(value) for value in sys.argv[1:]] +# python doesn't have a clean dict slice syntax; usually a comprehension +# is used (e.g. (mydict[key] for key in mykeys)), but that evaluates the +# dict expression more than once, so use itemgetter or a map + print( " ".join( - list( - map( - { - value: str(i + 1) - for i, value in enumerate(sorted(set(integers))) - }.__getitem__, - integers, - ) + operator.itemgetter(*integers)( + { + value: str(i + 1) + for i, value in enumerate(sorted(set(integers))) + } ) ) ) |
