Octal number problem

James J. Besemer jb at cascade-sys.com
Thu Feb 20 03:30:54 CET 2003

Gary Duncan wrote:

>     I have a list of 5-digit decimal numbers, which was constructed
> with leading zeroes where necessary so that the list is sorted by magnitude
> using Unix 'sort' (otherwise '00200' would appear before '1').

Sounds more like you have a list of STRINGS, not numbers.

If you want them to be interpreted as decimal, use the int() builtin 
function.  By default, it does a decimal conversion, ignoring the leading 0. 
  There's an optional base suffix that forces one of the standard bases or 
tells the converter to look at things like leading zero for octal.

If you kept your list as numbers in the first place, you could sort them and 200
would properly appear after 1.



James J. Besemer		503-280-0838 voice
2727 NE Skidmore St.		503-280-0375 fax
Portland, Oregon 97211-6557	mailto:jb at cascade-sys.com

More information about the Python-list mailing list