Task 1: First Unique Character
Task
You are given a string, $s
.
Write a script to find out the first unique character in the given string and print its index (0-based).
My solution
This is relatively straight forward task. Loop through the index from 0 to 2 less than the length of string. If that character occurs later in the string, print the index.
Examples
$ ./ch-1.py "The Weekly Challenge"
0
$ ./ch-1.py "Long Live Python"
3
Task 2: Trim List
Task
You are given list of numbers, @n
and an integer $i
.
Write a script to trim the given list where element is less than or equal to the given integer.
My solution
This is also straight forward. I start by pop
ing the last value from the list. I then use the for if function (grep for Perl) to get items in the list that are greater than that number.
Examples
$ ./ch-2.py 1 4 2 3 5 3
4, 5
$ ./ch-2.py 9 0 6 2 3 8 5 4
9, 6, 8, 5
Top comments (0)