Question

My nested for loop above end with

print print1,
print print2,
print print3,
print print4

which means i haven't yet appended or made a new data set, as i am a python beginner I do not know how. My output of data displays as:

Nameone 
Nametwoo
5454
62158
Nameoneooo
Nametwoooo
1212
21
Nameoneww 
Nametwoww
3455
21332

I'm trying to take the keep the 1st and 2nd lines together, not nessasary, but then compare the 3rd and 4th lines, the 4th line must be bigger in order to be true for me, so i only want to output the lines where that would be true. thus in the above sample code, only the middle 4 lines would end up outputting

[Nameone: Nametwo, 5454-62158], etc.
Was it helpful?

Solution

A simple example would be, instead of doing

for _ in range(_):
    print name1
    print name2
    print value1
    print value2

you could do,

values = []
for _ in range(_):
    values.append([name1, name2, value1, value2])

For your specified format (and if I understand it correctly), I would do

values = []
for _ in range(_):
    if value2 > value1:
        values.append([name1, name2, value2 - value1])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top