Last active
August 29, 2015 13:56
-
-
Save genghisjahn/9073039 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
def _sequential_ints(self, item_vals): | |
return len(item_vals) == len(set(item_vals)) == max(item_vals) - min(item_vals) + 1 | |
""" | |
len(item_vals) returns the number of items in the list. | |
len(set(item_vals)) returns the unique number of items in the list | |
If those == then we know there are no dupes in the list. | |
Lastly, if there are no dupes and the max value minus the min value (+1) | |
equals the len(item_vals), then we know that each int is sequential and that there are no duplicates. | |
+1 is added because with: | |
[5,6,7,8,9] If you subtract 5 from 9 you'll get 4. We add one to make sure it equals the length of the list. | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment