49384/python-code-to-find-if-an-array-is-monotonic
Hey Harsha, try out this code:
def monotonic(a): n = len(a) return (all(a[i]<=a[i+1] for i in range(n-1)) or all(a[i]>=a[i+1] for i in range(n-1))) a = [6, 5, 4, 3, 2] print(monotonic(a))
output:
True Process finished with exit code 0
Python doesn't have a native array data ...READ MORE
Slicing is basically extracting particular set of ...READ MORE
You can use python interpreter to check ...READ MORE
Since Python is open source you can ...READ MORE
You can also use the random library's ...READ MORE
Syntax : list. count(value) Code: colors = ['red', 'green', ...READ MORE
Enumerate() method adds a counter to an ...READ MORE
You can simply the built-in function in ...READ MORE
my_list = [1,2,3,4,5,6,7] len(my_list) # 7 The same works for ...READ MORE
You can use np.zeros(4,3) This will create a 4 ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.