On 7/11/2011 5:02 PM Edgar Almonte said...
back again,
yes that is the idea:
">  If I venture a guess, it seems to me that you want the debits and
corresponding offsetting credits listed in sequence."


but not sure if i get you pseudo code , you mean
some how flag the line when is D or C ( credit of debit )
and then sort by what ?


When you sort a list of tuple pairs, it sort on the first item, so

set sortkey to value+flag

means the first tuple in the list of tuples to sort should end up with as value+flag, where the flag is set based on the non-zero value in your line.

For example,

    XXXs,Dval,Cval = line.split("|")

then, assuming a consistent valid file structure,

    if int(Dval): key="D"+Dval
    else: key="C"+Cval

then, append (key,line) to your decorated list for each line, and finally sort and print the lines from your decorated list.

Emile


hello , i have a file this a structure like this
XXXXXXXXX XXXX| 0000000000000.00| 0000000088115.39|
XXXXXXXXX XXXX| 0000000090453.29| 0000000000000.00|

<snip>

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

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to