you could try something like this: iterate simultaneously over
x[:-1]
: the list without the last element
x[1:]
: the list without the first element
and compare the values. note that for equality you can compare the list elements as strings - but for <
and >
you probably want to convert them to float
before comparing.
x=['0.00', '0.00', '0.00', '7.79', '-1.63',
'-0.37', '-1.42', '-0.20', '0.16', '0.25']
for xj, xi in zip(x[:-1], x[1:]):
if xj == xi:
print '{} == {}'.format(xj, xi)
elif float(xj) < float(xi):
print '{} < {}'.format(xj, xi)
else:
print '{} > {}'.format(xj, xi)
output:
0.00 == 0.00
0.00 == 0.00
0.00 < 7.79
7.79 > -1.63
-1.63 < -0.37
-0.37 > -1.42
-1.42 < -0.20
-0.20 < 0.16
0.16 < 0.25
UPDATE:
after your comment it semst that you just want a list containing string telling you if the elements increase or not. this should work:
def comp_str(xj, xi):
if xj == xi:
return 'equal'
elif float(xj) < float(xi):
return 'yes'
else:
return 'no'
compare = [ comp_str(xj, xi) for xj, xi in zip(x[:-1], x[1:]) ]
print compare
# -> ['equal', 'equal', 'yes', 'no', 'yes', 'no', 'yes', 'yes', 'yes']