[Tutor] compare and arrange file

Edgar Almonte samudhio at gmail.com
Tue Jul 12 06:56:48 CEST 2011


thanks emile i understand exactly what you explain me but i was unable
to accomplish it ( too noob in python ) but i solved the problem with
this code
http://pastebin.com/4A6Jz4wZ

i will try do what you suggest me anyway but that will tomorrow ,
tonight i done and i feel good :D

Thanks all for the help

On Mon, Jul 11, 2011 at 11:01 PM, Emile van Sebille <emile at fenx.com> wrote:
> 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 at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list