Created
August 8, 2016 14:50
-
-
Save brainyfarm/de5b982980a57d3e848341ccec02d04e to your computer and use it in GitHub Desktop.
FreeCodeCamp: Where do I Belong (Python)
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
""" | |
Return the lowest index at which a value (second argument) | |
should be inserted into an array (first argument) once it has been sorted. | |
The returned value should be a number. | |
For example, getIndexToIns([1,2,3,4], 1.5) should return 1 | |
because it is greater than 1 (index 0), but less than 2 (index 1). | |
Likewise, getIndexToIns([20,3,5], 19) should return 2 | |
because once the array has been sorted it will look like [3,5,20] | |
and 19 is less than 20 (index 2) and greater than 5 (index 1). | |
Piece of cake ;) | |
""" | |
def getIndexToIns(the_list, num): | |
the_list.append(num) | |
the_list.sort() | |
return the_list.index(num) | |
print getIndexToIns([5, 3, 20, 3], 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment