[Tutor] compare and arrange file

Emile van Sebille emile at fenx.com
Tue Jul 12 00:39:47 CEST 2011


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
>
> maybe somebody can give some hint , i know that this is maybe not a
> directly python question but if somebody can help me I will appreciate
> it
>
> Thanks
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>




More information about the Tutor mailing list