- #1

WWGD

Science Advisor

Gold Member

- 5,561

- 4,604

- Summary:
- Given a list of Real numbers in Python , how do we tell if its terms are monotonic,i.e., if they are in strictly non-decreasing or strictly non-increasing order. I know how to do either one; either strictly increasing,strictly decreasing or both.

Given a list [ a,b,c,...., z] in Python, write a program to determine if the terms are monotonic or not. I can do either , and combine theminto a long, clunky program, but trying to see if I can find a succint way of doing both. I have heard that using ' Nums' may do it,but it seems too high-level for my taste.

For, say, non-decreasing we can do something like :

Similar for non-increasing.

And maybe I can do a kludge to join the code for both.

Someone suggested I look up 'Nums'.I did and it looks a bit high-level ( i.e., black-boxed').

Any idea to cover both cases in a single program?[/i][/code]

For, say, non-decreasing we can do something like :

Python:

```
List=L=[ a1, a2,...,an]
for i in in range(length(L)):
if L[i+1]-L[i] >=0:
return(' Yes,list is monotonic non-decreasing')
else:
print('No,not monotonic' non-decreasing)
```

And maybe I can do a kludge to join the code for both.

Someone suggested I look up 'Nums'.I did and it looks a bit high-level ( i.e., black-boxed').

Any idea to cover both cases in a single program?[/i][/code]

Last edited by a moderator: