strings and sort()

Sean 'Shaleh' Perry shalehperry at attbi.com
Wed Feb 20 21:08:00 EST 2002


On 21-Feb-2002 Jason wrote:
> How do I sort the characters in a string, so far I use this:
>         a="qwerasdfzxcv"
>         b=[x for x in a]
>         b.sort()
> 

b = list(a) # this works too

> Why doesn't sort() return the sorted list.  I would like to chain it
> to other operations:
>         b=[x for x in a].sort()
> 

efficiency.  Why return the sequence when we usually just need to sort the
list.  Sort is also a meothod of an object, why should it return a new object
instead of just affecting the one it belongs to?






More information about the Python-list mailing list