aboutsummaryrefslogtreecommitdiff
path: root/challenge-322
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-322')
-rw-r--r--challenge-322/ysth/python/ch-2.py18
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)))
+ }
)
)
)