aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2022-04-28 12:38:21 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2022-04-28 12:38:21 +0100
commit1f6e4c616cb20508f0c372289027f611adebdb22 (patch)
treedddcbff46afa1efe2cae414e9bd2deab8af1b778
parent21425cd7da79b2ea24c16958ce7a918ba4da69f2 (diff)
downloadperlweeklychallenge-club-1f6e4c616cb20508f0c372289027f611adebdb22.tar.gz
perlweeklychallenge-club-1f6e4c616cb20508f0c372289027f611adebdb22.tar.bz2
perlweeklychallenge-club-1f6e4c616cb20508f0c372289027f611adebdb22.zip
Add Python solution to challenge 040
-rw-r--r--challenge-040/paulo-custodio/python/ch-1.py34
-rw-r--r--challenge-040/paulo-custodio/python/ch-2.py33
2 files changed, 67 insertions, 0 deletions
diff --git a/challenge-040/paulo-custodio/python/ch-1.py b/challenge-040/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..5975a7c9d4
--- /dev/null
+++ b/challenge-040/paulo-custodio/python/ch-1.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+
+# Challenge 040
+#
+# TASK #1
+# Show multiple arrays content
+# You are given two or more arrays. Write a script to display values of each
+# list at a given index.
+#
+# For example:
+#
+# Array 1: [ I L O V E Y O U ]
+# Array 2: [ 2 4 0 3 2 0 1 9 ]
+# Array 3: [ ! ? @ $ % ^ & * ]
+# We expect the following output:
+#
+# I 2 !
+# L 4 ?
+# O 0 @
+# V 3 $
+# E 2 %
+# Y 0 ^
+# O 1 &
+# U 9 *
+
+def show_multiple(data):
+ for j in range(0, len(data[0])):
+ for i in range(0, len(data)):
+ print(data[i][j], end=" ")
+ print("")
+
+show_multiple([['I', 'L', 'O', 'V', 'E', 'Y', 'O', 'U'],
+ ['2', '4', '0', '3', '2', '0', '1', '9'],
+ ['!', '?', '@', '$', '%', '^', '&', '*']])
diff --git a/challenge-040/paulo-custodio/python/ch-2.py b/challenge-040/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..be8c13cdc3
--- /dev/null
+++ b/challenge-040/paulo-custodio/python/ch-2.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+
+# Challenge 040
+#
+# TASK #2
+# Sort SubList
+# You are given a list of numbers and set of indices belong to the list.
+# Write a script to sort the values belongs to the indices.
+#
+# For example,
+#
+# List: [ 10, 4, 1, 8, 12, 3 ]
+# Indices: 0,2,5
+# We would sort the values at indices 0, 2 and 5 i.e. 10, 1 and 3.
+#
+# Final List would look like below:
+#
+# List: [ 1, 4, 3, 8, 12, 10 ]
+
+data = [10, 4, 1, 8, 12, 3]
+indices = [0,2,5]
+
+def sort_sublist(data, indices):
+ values = []
+ for i in indices:
+ values.append(data[i])
+ values.sort()
+ for i in indices:
+ data[i] = values.pop(0)
+ return data
+
+data = sort_sublist(data, indices)
+print("["+(", ".join([str(x) for x in data]))+"]")