[Tutor] Re: Short Version, New guy looking for some tips, Revisited.

Lee Harr missive at hotmail.com
Sun Feb 8 10:28:51 EST 2004

>Your function -
>>def gen_list(somedir):
>>     l = os.listdir(somedir).sort()
>>     return l
>when I try that from the python interpreter it returns None.
>Im not sure why that is however.

In python, a_list.sort() sorts the list in place and returns None

>>>a_list = [4, 3, 5, 2, 1]
>>>r = a_list.sort()
[1, 2, 3, 4, 5]

so you would probably want ...

def gen_list(somedir):
    l = os.listdir(somedir)
    return l

My understanding is that in python2.4 lists will have a sorted() method
which will return the list sorted ...  or maybe it will be a builtin like 
s = sorted(a_list)

STOP MORE SPAM with the new MSN 8 and get 2 months FREE* 

More information about the Tutor mailing list