how do i change from string to list

Ivo Woltring TheDolphin at ivonet.nl
Sun Oct 24 20:16:50 CEST 2004


str='spot'

lst = [] # declare the list first
for letter in str:
    lst.append(letter) # append to the list

print lst

result: ['s', 'p', 'o', 't']

cheerz,
Ivo.


"john" <miodio67 at hotmail.com> wrote in message
news:99ca2e2f.0410241005.39a4f1db at posting.google.com...
> I have the following
>
> s = "spot"
>
> which I would like to change to a list
>
> l = ['s','p','o','t']
>
> I have tried  l = eval(s) but I get the error
>
> File "<string>", line 1, in ?
> NameError: spot
>
> thank you all for your time





More information about the Python-list mailing list