[Tutor] How to group data?

Dave Angel davea at ieee.org
Mon Feb 14 01:15:31 CET 2011


On 02/13/2011 07:03 PM, tee chwee liong wrote:
>
>> How about some clues as to what you're trying to accomplish? This code
>> is surprisingly verbose, and probably totally wrong. Anyway, each time
>> you pop an item from the list, all the following ones change their
>> index. So presumably there weren't still 79 items in the list by the
>> time you had removed and shuffled a bunch of them. You don't indicate
>> how many times it went around the outer loop, but in any case, there
>> won't be enough values the last time around.
>>
>
> sorry for the confusion. i'm trying to get:
>>>>
> ROW1=1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> ROW2=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> ROW3=XX11111X11XXXXX11XXXXXX1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> ROW4=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XXXXXXXXXX1XXXXXXXXXXXX111111XXXX
>
> whereby it will group the last column in the data file into each row with 128 characters in reverse order. for eg: in data below and if i group it into 4 characters in a row in reverse order will be:
>
> row1=XX11
> row2=XXXX
> row3=XXXX
> row4=00XX
>
> 0 BC_4 SYSCLK_DN observe_only 1
> 1 BC_4 SYSCLK_DP observe_only 1
> 2 BC_4 QPI3_DRX_DN 19 input X
> 3 BC_4 QPI3_DRX_DP 19 input X
> 4 BC_4 QPI3_DRX_DN 18 input X
> 5 BC_4 QPI3_DRX_DP 18 input X
> 6 BC_4 QPI3_DRX_DN 17 input X
> 7 BC_4 QPI3_DRX_DP 17 input X
> 8 BC_4 QPI3_DRX_DN 16 input X
> 9 BC_4 QPI3_DRX_DP 16 input X
> 10 BC_4 QPI3_DRX_DN 15 input X
> 11 BC_4 QPI3_DRX_DP 15 input X
> 12 BC_4 QPI3_DRX_DN 14 input X
> 13 BC_4 QPI3_DRX_DP 14 input X
> 14 BC_4 QPI3_DRX_DN 13 input 0
> 15 BC_4 QPI3_DRX_DP 13 input 0
>    		 	   		

It still makes no sense to me.

If you need to reverse a string, use [::-1] idiom
For example,
      a = "abcde"
      print a[::-1]
will print edcba

Hope that helps in some way.  But I don't understand what you're trying 
to do, and the example above doesn't make it any clearer.

DaveA


More information about the Tutor mailing list