Two newbie questions

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Tue Jun 13 12:55:54 EDT 2000


Arkaitz wrote in comp.lang.python:
> Hi all,
> 
> I'm learning Python, as it seems everybody around here :-), and I found two 
> problems that I can't find the solution to:
> 1. As the strings are inmutable, if I want to modify the order of the characters
> in the string(e.g. sort them), what I do is:
> 
> st = "asdfasfasdf"
> l = []
> for c in st:
>     l.append(c)
> 
> Then I process the list, and the problem is that I have no idea of how I can get
> the string back, any help?

import string

st = "asdgasfasdf"
l = list(st) # A simpler way to make the list
l.sort() # Do something, e.g. sort
st = string.join(l, "")

-- 
Remco Gerlich,  scarblac at pino.selwerd.nl
  6:53pm  up 99 days,  7:07,  6 users,  load average: 0.01, 0.10, 0.13



More information about the Python-list mailing list