In following part:
[i] < [i + 1]
You are putting the list items in list and add 1 to one of them and compare them which is wrong.
If you want to access to previous item of each item you need to decrease it's index 1 unit and access to its relative item by a simple indexing like L[1]
which will gives you the second items of your list.
Also as a more pythonic way for accessing to all pair of a list items you can use zip
function.For example:
>>> L=range(7)
>>> L
[0, 1, 2, 3, 4, 5, 6]
>>>
>>> zip(L,L[1:])
[(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
Note: in pyhton 3.X zip
returns an iterator (which doesn't makes any different when you want to loop over the result).
And then you can loop over the result like following:
for i,j in zip(L,L[1:]):
# do something
And finally about your task since you want to count the number of this pairs which the second items is larger than the first you can use a generator expression within sum
function:
sum(j>i for i,j in zip(L,L[1:]))
Note that since the result of j>i
is a boolean value and python will evaluate the True as 1 and False as 0 at the end it will comes up with the expected count of those pairs that follow your criteria.