Fwd: Re: [Tutor] sort()

Magnus Lycka magnus@thinkware.se
Wed, 02 Oct 2002 20:52:28 +0200


>From: Annika Scheffler <annika.scheffler@gmx.net>
>Subject: Re: [Tutor] sort()
>
>Hi,
>
>thanks for everyone for your help!
>I'm afraid I have another question...:
>
>For example, I have a list like this: l =3D "What Do we have here".split().
>If I use the sort() method on this list I get:
>['Do', 'What', 'have', 'here', 'we']
>What I want as a result is this, though:
>
>['Do', 'have', 'here', 'we', 'What']
>
>In other words, I'd like the sort() method to ignore the first letter of
>each word being lower or uppercase. How can I do that?

I think someone already answered that.

def caseIndependentSort(this, that):
     return cmp(this.lower(), that.lower())

l.sort(caseIndependentSort)




--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se