Created
April 10, 2021 05:57
-
-
Save VeldaKiara/c5d98ebca8a71e7889f1aa6c9ad916a9 to your computer and use it in GitHub Desktop.
This is a list of the algorithms I will be solving.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nums = [0, 0, 1, 1, 2, 2, 3, 3, 4] | |
| #using list comprehension to remove duplicates | |
| non_dup = [] | |
| [non_dup.append(x) for x in nums if x not in non_dup] | |
| print(str(non_dup)) | |
| print(len(non_dup)) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @meekg33k, I am happy to participate.
I totally missed that I was supposed to exclusively use a function. I used a list comprehension because of time, I thought it would be faster and compact as compared to using a regular loop.
And yes my solution assumed that there will be no case where the result is null.
Something I have learned from doing this challenge is to ask the right questions and not to base the solution on my assumptions and instructions or requirements are as important as solving the problem.
And as much as I want to make the solution compact I need to account for edge cases.
I will write another solution that accounts for the edge cases and uses a function.
Thank you for the feedback as well as the challenge.
I cannot wait for the next challenge.