I'm trying to solve the following problem: I have a file which is build like this:
adsbhad 2.2 3.2 5.2 3.2 7.2
gsdg 1.2 2.2 5.7 8.2 10.2
sdgghhad 1.2 0.2 3.2 2.2 5.2
adsdfhad 0.2 1.2 5.2 8.2 12.2
adrzertzd 1.2 13.2 2.2 10.2 9.2
I want to write a script which checks if the values in the lines are only getting bigger and then extract those lines. In this case the desired lines are line 2 and 4:
gsdg 1.2 2.2 5.7 8.2 10.2
adsdfhad 0.2 1.2 5.2 8.2 12.2
I tried to use for loops and if statements but it doesn't work. It seems that there are some type-issues. Here is my code so far (please be kind because I'm a beginner!):
Data=raw_input("Please type name of input data! ")
Data2=open(Data)
new_list=list()
for line in Data2:
line2=line.rstrip()
first_empty=line2.find(" ")
line3=line2[first_empty+1:]
List_of_line=line3.split()
express=0
for i in List_of_line:
flo_i=float(i)
express=float(express)
if express == 0 or flo_i > express:
express=flo_i
express=str(express)
if express == List_of_line[4]:
print List_of_line
I also tried to replace the list-for loop with if statements but this doesn't work and I don't know why. I also converted to float within the if statements but there was no change.
I thought this is easy to solve but it is not (well, for me) and so I hope I get some help. Thanks in advance.