From 29b273fc146113e127bd1664dd8d198d4ad2dcbd Mon Sep 17 00:00:00 2001 From: deadmarshal Date: Fri, 2 Sep 2022 11:13:08 +0430 Subject: challenge180 --- challenge-180/deadmarshal/python/ch1.py | 20 ++++++++++++++++++++ challenge-180/deadmarshal/python/ch2.py | 9 +++++++++ 2 files changed, 29 insertions(+) create mode 100644 challenge-180/deadmarshal/python/ch1.py create mode 100644 challenge-180/deadmarshal/python/ch2.py (limited to 'challenge-180/deadmarshal/python') diff --git a/challenge-180/deadmarshal/python/ch1.py b/challenge-180/deadmarshal/python/ch1.py new file mode 100644 index 0000000000..a006f46cb3 --- /dev/null +++ b/challenge-180/deadmarshal/python/ch1.py @@ -0,0 +1,20 @@ +import sys + +def first_unique_character(s): + freq = {} + for i in s: + if i not in freq: + freq[i] = 1 + else: + freq[i] += 1 + + for i in range(len(s)): + if(freq[s[i]] == 1): + return f"{i} as '{s[i]}' is the first unique character" + return -1 + +if(len(sys.argv) != 2): + sys.stderr.write("No arg(s) provided!\n") + sys.exit(1) + +print(first_unique_character(sys.argv[1])) diff --git a/challenge-180/deadmarshal/python/ch2.py b/challenge-180/deadmarshal/python/ch2.py new file mode 100644 index 0000000000..7522545459 --- /dev/null +++ b/challenge-180/deadmarshal/python/ch2.py @@ -0,0 +1,9 @@ +def trim_list(arr, i): + return list(filter(lambda x: x > i, arr)) + +i,i2 = 3, 4 +n = [1,4,2,3,5] +n2 = [9,0,6,2,3,8,5] + +print(trim_list(n, i)) +print(trim_list(n2, i2)) -- cgit