[Tutor] improve the code
Alan Gauld
alan.gauld at btinternet.com
Wed Nov 2 21:22:33 CET 2011
On 02/11/11 16:58, Dave Angel wrote:
>>>>> sorted(results)
>> ['10B', '1A', '2C', '3D']
>>
>> as [ '1A', '2C', '3D','10B']
> Essence of the answer is you can supply a key=myfunc argument to
> sorted(). Then it's up to you what you put in that function. It sounds
> like you want to convert any leading digits to an int, and return that int.
Or in your case it might be hex in which case convert the whole string
using int and specify the base to be 16...
>>> int('1A',16)
26
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list