Not sure how to do this I tried googling it but to no avail. I want to print out a specific line in my while loop

450 42.5 16625.0
460 42.0 16820.0
470 41.5 17005.0
480 41.0 17180.0
490 40.5 17345.0
500 40.0 17500.0

example of part of my output loop I would like to print out the line before the price starts to drop.


So essentially my output would look like this

450 42.5 16625.0
460 42.0 16820.0
470 41.5 17005.0
480 41.0 17180.0
490 40.5 17345.0
500 40.0 17500.0
XXXX is 470
XXXX is 41.5
XXXX is 17005.0

Recommended Answers

All 5 Replies

What you mean, last number goes up, second down all time.

Not sure what you are talking about.

You have to explain yourself better.
Just one way to take out a line.

data = '''\
450 42.5 16625.0
460 42.0 16820.0
470 41.5 17005.0
480 41.0 17180.0
490 40.5 17345.0
500 40.0 17500.0'''

for line in data.split('\n'):
    if line.startswith('470'):
        print line
        #470 41.5 17005.0

If really last data would go down like you said in text:

data = '''
450 42.5 16625.0
460 42.0 17820.0
470 41.5 17005.0
480 41.0 17180.0
490 40.5 17345.0
500 40.0 17500.0
'''

prev = ''

for line in data.split('\n'):
    splitted_line = line.rsplit(None,1)
    if splitted_line:
        if splitted_line[-1] < prev:
            print line
            break
        prev = splitted_line[-1]

The way I'm interpreting it is like:

that='''450 42.5 16625.0
460 42.0 16820.0
470 41.5 17005.0
480 41.0 17180.0
490 40.5 17345.0
500 40.0 17500.0'''

this=that.split('\n')
price=None
for info in this:
    data=info.split()
    if price==None:
        price=data[1]
    elif data[1]<price:
        for info in data:
            print('XXXX is %s'%info)
        break

output:

>>> 
XXXX is 460
XXXX is 42.0
XXXX is 16820.0
>>>

but your saying the price starts to drop and I don't know if the second one is the price or the first or the third... you didn't give us enough info to go on...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.