Skip to content

Instantly share code, notes, and snippets.

@genghisjahn
Last active August 29, 2015 13:56
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 genghisjahn/9073039 to your computer and use it in GitHub Desktop.
Save genghisjahn/9073039 to your computer and use it in GitHub Desktop.
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