[Beds] python question

Darren Parkinson DParkinson at touchbase.co.uk
Tue Mar 22 20:50:43 GMT 2005


I think you can do this in the following way:

string = 'abcde'
items = [ word[0] for word in string ]
print items
print items[0]

Is this what you mean?  I've just downloaded it too so not sure if this
is the right answer, but it seems to work...  Certainly prints ['a',
'b', 'c', 'd', 'e'] and a respectively...  Would seem that this is
unexpected functionality since this is supposed to take the first letter
of each word... (I was pretty lucky with google :))

Regards,
Darren.


-----Original Message-----
From: Lee Larcombe [mailto:lee at larcombe.uk-internet.org.uk] 
Sent: 22 March 2005 20:13
To: beds at mailman.lug.org.uk
Subject: [Beds] python question


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

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________



More information about the Beds mailing list