DEV Community 👩‍💻👨‍💻

Simon Green
Simon Green

Posted on

Weekly Challenge 180

Challenge, My solution

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
Enter fullscreen mode Exit fullscreen mode

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 poping 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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

🌚 Life is too short to browse without dark mode