Here is on more go ! Need a shortcut for my problem !
problem is i have a look_update with fixed sequence of column
that is :
MANDT:SERAIL:SERSCHA:SEREX:EQTYP:BSTVP
I will be getting data in a flat file having same number of column but the sequence could be different in each time
for example
SERAIL MANDT SERSCHA SEREX EQTYP BSTVP
510 1 f g s r
510 2 g S t
510 3 g S 2
510 4 g S 2
510 Z001 g S
510 Z004 f gr S 2
510 ZPM1 f er M 1
510 ZPM2 76 M 1
here the sequence of the column is not what it in look up string
it should be in the sequence of look up string .
I want to arrange the data of this table in look up sequence and put it into another filnal_data file
each time the clientdata may come in differnt sequence but i have arrange the column in the sequence of lookup_string and append it to final table
Dhruv,
Here is the problem again ..
I have a fixed look up file whose column are in fixed sequence say..
"MANDT SERAIL SERSCHA SEREX EQTYP BSTVP"
i have stored this sequence in a variable ..
Now
I am getting data file whose column sequence could be differnt from that i have mention in the look up string .
I want to resuffle this data file according to the column sequence of the look_up string.
see the sequence of these file each time sequence of column varies .
the final reaange of these file should be based on the column of the look up[ string always.
Ok
1
Now i want to resuffle this data file so that the column starting with
MANDT should come first then SERAIL ...then SERSCHA SEREX EQTYP
and the final resuffle data should append to a file name say final_data.txt
def transpose(matrix):
return [[matrix[y][x] for y in range(len(matrix))]for x in range(len(matrix[0]))]
all = open("input.txt").readlines()
lookupstring = ['MANDT', 'SERSCHA','SERAIL' , 'SEREX', 'EQTYP', 'BSTVP']
listing = [ i.split() for i in all ]
results = transpose(listing)
final= [ r for items in lookupstring for r in results if items == r[0] ]
for i in transpose(final):
print ','.join(i)