How to sort records in file

Grant Edwards grante at visi.com
Fri Aug 13 21:29:18 CEST 2004


On 2004-08-13, Lad <export at hope.cz> wrote:

> What is the best( easiest)way how to sort a file?

$ man sort  

;)

> I have a file where each record consists of 3 fields( 3 words)
> and I would like to sort records by the first field( word)in
> each record.

lines = file('myfilename').readlines()
lines.sort()
for l in lines:
    print l,

-- 
Grant Edwards                   grante             Yow!  I just had my entire
                                  at               INTESTINAL TRACT coated
                               visi.com            with TEFLON!



More information about the Python-list mailing list