aboutsummaryrefslogtreecommitdiff
path: root/challenge-263/steven-wilson/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-263/steven-wilson/python/ch-1.py')
-rw-r--r--challenge-263/steven-wilson/python/ch-1.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-263/steven-wilson/python/ch-1.py b/challenge-263/steven-wilson/python/ch-1.py
new file mode 100644
index 0000000000..c5812d1069
--- /dev/null
+++ b/challenge-263/steven-wilson/python/ch-1.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+
+def target_index(*elements, target):
+ ''' Given an array of integers and a target element, return the list of
+ indices in the sorted array where the element is same as the given target
+ element.
+ >>> target_index(1, 5, 3, 2, 4, 2, target=2)
+ [1, 2]
+ >>> target_index(1, 2, 4, 3, 5, target = 6)
+ []
+ >>> target_index(5, 3, 2, 4, 2, 1, target = 4)
+ [4]
+ '''
+ return [i for i, elem in enumerate(sorted(elements)) if elem == target]
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod()