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 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 challenge-180/deadmarshal/python/ch1.py (limited to 'challenge-180/deadmarshal/python/ch1.py') 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])) -- cgit