Last active
August 6, 2016 00:23
-
-
Save sejr/4cd0ed52d22a429ac37eecd192020651 to your computer and use it in GitHub Desktop.
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
| # coding: utf-8 | |
| def find_position(i, array): | |
| input_added = False | |
| for index, value in enumerate(array): | |
| if i < value: | |
| array.insert(index, i) | |
| input_added = True | |
| return 1 | |
| if input_added == False: | |
| array.append(i) | |
| return 1 | |
| def dropsort(array): | |
| print array | |
| result = [] | |
| result.append(array[0]) | |
| array.pop(0) | |
| for index, input in enumerate(array): | |
| find_position(input, result) | |
| return result | |
| if __name__ == '__main__': | |
| testA = [1, 4, 7, 17, 13, 8, 22] | |
| testB = [7, 100, -628, -2, 381] | |
| print dropsort(testA) | |
| print dropsort(testB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment