[Tutor] (no subject)

Gonçalo Rodrigues op73418@mail.telepac.pt
Wed, 2 Oct 2002 12:23:55 +0100


----- Original Message -----
From: "Annika Scheffler" <annika.scheffler@gmx.net>

> Hi Rob,
>
> Thanks for your help! In fact, it does work that way for me, too. But when
> writing a function like this:
>
> def sortList(someList):
>
>
>           return someList.sort()
>
> print sortList("What have we here".split())
>
> I get "none" as a result. Why's that?
>
> Thanks,
> Annika
>

Look at the expression:

someList.sort()

Remember that all functions, methods, etc return *something* and sort()
returns None, so the above evaluates to None. The sort() method does an
in-place sort, so what you want is

someList.sort()
return someList

Hope it helps,
Gonçalo Rodrigues