sorting contacts alphabetically, sorted by surname

Boris Borcic bborcic at gmail.com
Fri Nov 16 15:32:55 CET 2007


Wow

J. Clifford Dyer wrote:
> On Fri, Nov 16, 2007 at 12:31:19PM +0000, Marie Hughes wrote regarding sorting contacts alphabetically, sorted by surname:
>>    HI
>>
>>    I have to write a program that contains a text file in the following
>>    format:
>>
>>    Academic            Position                Room Ext.       Email
>>    Prof Marie Maguire  Head of
>>    School      M9002 0000   [1]lp.muire at ulioooor.ac.uk
>>
>>    And produce a output file where conatcts are sorted alphabetically-
>>    sorted by surname.
>>
>>    Has anyone any ideas.
> 
> Well, the first thing you need to do is develop a workable understanding of how your data file is formatted.  What separates one field from another?  Is it tab-delimited?  Does the field always start at a given column number?  Then you need to read each line of the file, and split the lines up according to the format.  Save to a data structure, sort by last name (you'll have to further parse the name to isolate this information), and reprint the results.
> 
> Depending on the details you uncover about the precise format of your data file, you will find it helpful to read the documentation on string methods, particularly s.split(), and sequence slicing: s[4:14].
> 
> Best of luck with it.
> 
> Cheers,
> Cliff




More information about the Python-list mailing list