Skip to content

Instantly share code, notes, and snippets.

@M-Bryant
Created December 14, 2016 00:53
Show Gist options
  • Save M-Bryant/049d9e45bf0b749bc715de9eb70b22fc to your computer and use it in GitHub Desktop.
Save M-Bryant/049d9e45bf0b749bc715de9eb70b22fc to your computer and use it in GitHub Desktop.
Set of python functions for checking list of number increasing
def strictly_increasing(L):
"""Returns TRUE if the values in the list are strictly increasing
Always increasing; never remaining constant or decreasing or null.
"""
return all(x<y for x, y in zip(L, L[1:]))
def strictly_decreasing(L):
"""Returns TRUE if the values in the list are strictly decreasing
Always decreasing; never remaining constant or increasing or null.
"""
return all(x>y for x, y in zip(L, L[1:]))
def non_decreasing(L):
"""Returns TRUE if values in the list are increasing.
Allows for values remaining constant. Does NOT allow null
"""
return all(x<=y for x, y in zip(L, L[1:]))
def non_increasing(L):
"""Returns TRUE if values in the list are decreasing.
Allows for values remaining constant. Does NOT allow null
"""
return all(x>=y for x, y in zip(L, L[1:]))
def not_strictly_increasing(L):
# strip leading null values
while len(L)!=0 and L[0] is None: L.pop(0)
# check list has monotonically increasing values
# this returns TRUE if values are increasing
strictly_increasing = all(x<y for x, y in zip(L, L[1:]))
# invert the return value
return not(strictly_increasing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment