sequence of elements problem

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

sequence of elements problem

This post has NOT been accepted by the mailing list yet.
Hi, I have a problem in python which is kind of tricky.

if i give a sequence of numbers, i should get another sequence of numbers such that the the elements exceeds previous element in the list. For eg

seq_num([3,2,5,7])=[3,5,7] since 5 is >3, and 7>5
seq_num([1,2,3,4])=[1,2,3,4]  since 2 is >1, and 3>2 and so on

and so on without using any inbuilt functions.

I tried the following code but it is not incrementing:

def seq_num(numlist):

    for i in range(0,n - 1):
        if numlist[i]>numlist[i+1]:
            return numlist[i]