sorting a file
jim-on-linux
inq1ltd at inqvista.com
Sat Jun 14 12:00:20 EDT 2008
On Saturday 14 June 2008 03:15, Beema
shafreen wrote:
> Hi all,
>
> I have a file with three columns i need
> to sort the file with respect to the third
> column. How do I do it uisng python. I
> used Linux command to do this. Sort but i
> not able to do it ? can any body ssuggest
> me
I have used this method to solve similar
problems.
This is a consept of how to do what you want,
but you will have to work a little to get it
right.
You might try something like this;
Dict = {} ##create a dictionary
make a list of all column3 values
for loop colum3 values
Make these values the key in a dictionary
If the values are long, you can use the first
7 to 15 characters if you want.
use this key to equal all the values in the
other columns on the same row.
Dict[column3] = column1, column2, column3
once the dictionary is made
get the dictionary key
x = Dict.keys() ## get the keys from Dict
x.sort() # produce a sorted list of keys of
column3
Loop these sorted keys to extract from the
dictionary the values related to each
jim-on-linux
http://:inqvista.com
More information about the Python-list
mailing list