Skip to content

Instantly share code, notes, and snippets.

@YisroelLen
Last active October 18, 2019 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YisroelLen/530ab755c2b99a8617fe0744f08085f9 to your computer and use it in GitHub Desktop.
Save YisroelLen/530ab755c2b99a8617fe0744f08085f9 to your computer and use it in GitHub Desktop.
Coding Challenge description and explanation
def sum_two_smallest_numbers(numbers):
# First let's get rid of any numbers that are below 0.
# We'll create a new list that will only have positive numbers in it.
new_list = []
# Place the positive numbers in the list
for num in numbers:
if num >= 0:
new_list.append(num)
# Next we need to find the two lowest numbers in the list.
# There are several possibilities but we'll go with the simplest one.
# Let's sort the new list from least to greatest
new_list = sorted(new_list)
# Now we can just add the numbers at the 0th and the 1st index
return (new_list[0] + new_list[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment