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

Nick Lunt nick at javacat.f2s.com
Sun Feb 8 11:57:07 EST 2004


Thanks for clearing that up ;)



On Sun, 08 Feb 2004 15:28:51 +0000
"Lee Harr" <missive at hotmail.com> wrote:

> >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()
> >>>r
> >>>a_list
> [1, 2, 3, 4, 5]
> >>>
> 
> 
> so you would probably want ...
> 
> def gen_list(somedir):
>     l = os.listdir(somedir)
>     l.sort()
>     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* 
> http://join.msn.com/?page=features/junkmail
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list