[Beds] python question

Stephen Newey stephen at freakymousemats.com
Tue Mar 22 20:42:50 GMT 2005


'ello

A string in Python is an immutable list, so you can treat it just like 
one, eg:

for char in string:
    print char

Or...

print string[1:3]

To make it a regular list you could...

array = []
for char in string: array.append(char)

I'm pretty sure there's a better way of doing that, just don't recall 
it right now :)

Hope that helps
Steve


On 22 Mar 2005, at 20:12, Lee Larcombe wrote:

> Hi
>
> I am trying to learn python, and i have hit a problem I can't find a 
> solution for.
>
> I want to split a string into a list - ie
>
> string = 'abcde'
>
> would become
>
> list = ['a', 'b', 'c', 'd', 'e']
>
> I can do this in perl by using:
>
> @array= unpack("A1" x length($string), $string);
>
> Can anyone tell me a python way of doing this???
>
> I know python could use string.split(";") to split a string on a 
> delimiter (; in this case) but there doesn't seem a way to use split 
> without a delimiting character
>
> I can't believe this is impossible - please help!!!
>
> Lee.
>
>
> _______________________________________________
> Beds mailing list
> Beds at mailman.lug.org.uk
> http://mailman.lug.org.uk/mailman/listinfo/beds




More information about the Beds mailing list