Thanks for the hints , what i want accomplish is sort the line by the same value in the column 2 and 3
i mean the line with the same value in the 2 get together with the line in the same value in column 3 emile and david thanks again let me check the hint that your give me, i will feedback the code if everything workout or else :D On Mon, Jul 11, 2011 at 7:35 PM, Dave Angel <d...@davea.name> wrote: > On 07/11/2011 06:39 PM, Emile van Sebille wrote: > > On 7/11/2011 3:16 PM Edgar Almonte said... > > hello , i have a file this a structure like this > XXXXXXXXX XXXX| 0000000000000.00| 0000000088115.39| > XXXXXXXXX XXXX| 0000000090453.29| 0000000000000.00| > XXXXXXXXX XXXX| 0000000000000.00| 0000000090443.29| > XXXXXXXXX XXXX| 0000000088115.39| 0000000000000.00| > XXXXXXXXX XXXX| 0000000000000.00| 0000000088335.39| > XXXXXXXXX XXXX| 0000000090453.29| 0000000000000.00| > XXXXXXXXX XXXX| 0000000088335.39| 0000000000000.00| > XXXXXXXXX XXXX| 0000000090443.29| 0000000000000.00| > > now i need re-arrange the file in this way: > XXXXXXXXX XXXX| 0000000000000.00| 0000000088115.39| > XXXXXXXXX XXXX| 0000000088115.39| 0000000000000.00| > XXXXXXXXX XXXX| 0000000000000.00| 0000000090453.29| > XXXXXXXXX XXXX| 0000000090453.29| 0000000000000.00| > > etc.... > > It's not obvious to me for your sample what you want. For example, the 2nd > value 0000000090453.29 from the re-arranged group doesn't appear in the top > sample. > > If I venture a guess, it seems to me that you want the debits and > corresponding offsetting credits listed in sequence. > > In pseudo-code, that might me done as: > > read lines from file > for each line in lines > set flag to D or C based on values > set sortkey to value+flag > append sortkey and line to decorated list > sort decorated list > for key,line in decorated list > print line > > > HTH, > > Emile > > > > > > i try this > http://pastebin.com/2mvxn5GY > but without look > > I also can't see any pattern in the data to give a clue what kind of > filtering you're trying to do. A more specific spec would be useful. > > I can comment on your pastebin code, however. You should have pasted it in > your message, since it's short. > > def splitline(line, z): > if z == 0: > pass > > fields = line.split('|') > nlist = [] > for field in fields: > nlist.append(field) > > return nlist[z] > > The whole loop with nlist is a waste of energy, as you already got a list > from split(). You could replace the function with > def splitline(line, z): > return line.split('|')[z] > > The if z==0 doesn't do anything either. Perhaps you meant to do some error > checking in case the line doesn't have at least z fields. > > But the real problem in your code is the you posted for loop. The inner > loop takes multiple passes through the orig1 file, but the second time won't > get anything, since the file is already positioned at the end. I'd simply > move the open statement inside the outer loop. > > There may be other problems, but that could get you going. > > DaveA > > > > > > > > -- > > DaveA > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor