aboutsummaryrefslogtreecommitdiff
path: root/challenge-263/dave-jacoby/python
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2024-04-02 19:00:21 -0400
committerDave Jacoby <jacoby.david@gmail.com>2024-04-02 19:00:21 -0400
commitae28c878d0b2588ba22c34975e046543572acfb2 (patch)
tree34e1f372fae39e0ef66ce24df8fa4b9c4933ceee /challenge-263/dave-jacoby/python
parentf1be0a7ea43632d0763a7506d164a61ccddc6b06 (diff)
downloadperlweeklychallenge-club-ae28c878d0b2588ba22c34975e046543572acfb2.tar.gz
perlweeklychallenge-club-ae28c878d0b2588ba22c34975e046543572acfb2.tar.bz2
perlweeklychallenge-club-ae28c878d0b2588ba22c34975e046543572acfb2.zip
DAJ 263
Diffstat (limited to 'challenge-263/dave-jacoby/python')
-rw-r--r--challenge-263/dave-jacoby/python/ch-1.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-263/dave-jacoby/python/ch-1.py b/challenge-263/dave-jacoby/python/ch-1.py
new file mode 100644
index 0000000000..7490ef961c
--- /dev/null
+++ b/challenge-263/dave-jacoby/python/ch-1.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+def main():
+ examples = [ { 'k':2, 'ints':[1, 5, 3, 2, 4, 2 ] }, { 'k':6, 'ints':[1, 2, 4, 3, 5 ] }, { 'k':4, 'ints':[5, 3, 2, 4, 2, 1 ] } ]
+ for e in examples:
+ output = target_index( e )
+ o = ",".join(output)
+ ints = e["ints"].copy()
+ i = ','.join(map(str,ints))
+ k = str(e["k"])
+ print("Input: k={}, i=[{}]\nOutput: output=[{}]\n".format(k,i,o))
+
+def target_index( obj ):
+ output = []
+ k = obj["k"]
+ ints = obj["ints"].copy()
+ ints.sort()
+ for i, item in enumerate(ints):
+ if item == k:
+ output.append(str(i))
+ return(output)
+
+if __name__ == '__main__':
+ main()