aboutsummaryrefslogtreecommitdiff
path: root/challenge-284/zapwai/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-284/zapwai/python/ch-2.py')
-rw-r--r--challenge-284/zapwai/python/ch-2.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-284/zapwai/python/ch-2.py b/challenge-284/zapwai/python/ch-2.py
new file mode 100644
index 0000000000..7e1c4bb38b
--- /dev/null
+++ b/challenge-284/zapwai/python/ch-2.py
@@ -0,0 +1,32 @@
+def proc(l1, l2):
+ print("Input: \n list1 =", l1, "\n list2 =", l2)
+ tail = []
+ for item in list1:
+ elem_of_l2_flag = 0
+ for item2 in list2:
+ if item == item2 :
+ elem_of_l2_flag = 1
+ break
+
+ if elem_of_l2_flag == 0 :
+ tail.append(item)
+ pre = []
+ for item2 in list2 :
+ for item in list1 :
+ if item == item2 :
+ pre.append(item)
+ tail.sort();
+ out = pre
+ for t in tail:
+ out.append(t)
+ print("Output:", out)
+
+list1 = [2, 3, 9, 3, 1, 4, 6, 7, 2, 8, 5]
+list2 = [2, 1, 4, 3, 5, 6]
+proc(list1, list2)
+list1 = [3, 3, 4, 6, 2, 4, 2, 1, 3]
+list2 = [1, 3, 2]
+proc(list1, list2)
+list1 = [3, 0, 5, 0, 2, 1, 4, 1, 1]
+list2 = [1, 0, 3, 2]
+proc(list1, list2)