0 votes
I'm trying to write a python code to find if an array is monotonic. Can you help me out with it? Thank you.
Jun 17, 2019 in Python 2,195 views

## 1 answer to this question.

0 votes

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```
answered Jun 17, 2019 by Yesha

+4 votes
7 answers

## What is an array in Python? How to declare it?

Python doesn't have a native array data ...READ MORE

0 votes
1 answer

## How to slice an array using python numpy? Is there any numpy tutorial which has covered all its operations?

Slicing is basically extracting particular set of ...READ MORE

0 votes
1 answer

## How to find if setuptools is installed in python?

You can use python interpreter to check ...READ MORE

0 votes
1 answer

## Is it possible to find the source code of built-in functions of Python?

Since Python is open source you can ...READ MORE

0 votes
2 answers

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote
2 answers

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

0 votes
1 answer

## how do i use the enumerate function inside a list?

Enumerate() method adds a counter to an ...READ MORE

+5 votes
6 answers

## Lowercase in Python

You can simply the built-in function in ...READ MORE

0 votes
1 answer

## Is arr.__len__() the preferred way to get the length of an array in Python?

my_list = [1,2,3,4,5,6,7] len(my_list) # 7 The same works for ...READ MORE

0 votes
1 answer

## Is it possible to create an array with all values as zero in python?

You can use  np.zeros(4,3) This will create a 4 ...READ MORE