strings and sort()
scarblac at pino.selwerd.nl
Thu Feb 21 08:41:39 CET 2002
Jason <caljason76 at yahoo.com> wrote in comp.lang.python:
> How do I sort the characters in a string, so far I use this:
> b=[x for x in a]
Yes. Instead of b=[x for x in a] you can use b = list(a).
> Why doesn't sort() return the sorted list. I would like to chain it
> to other operations:
> b=[x for x in a].sort()
sort() sorts the list in place, probably because that's usually what you
want. Methods that change the object in place typically don't return the
object, or people might think that the object wasn't changed.
People might believe that b wasn't changed. To avoid confusion, you can't do
More information about the Python-list