>How do I split a string like "Hans" into a list of characters
> ['H','a','n','s']?
>>> list('fred')
['f', 'r', 'e', 'd']
>>>
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist - Tu
Bingo :)
Thanks Rick
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Rick Pasotto
Sent: Tuesday, 23 August 2005 1:55 p.m.
To: tutor@python.org
Subject: Re: [Tutor] Split a string into characters
On Tue, Aug 23, 2005 at 01:18:43PM +1200, Hans
On Tue, Aug 23, 2005 at 01:18:43PM +1200, Hans Dushanthakumar wrote:
> Hi,
>A quick one...
>How do I split a string like "Hans" into a list of characters
> ['H','a','n','s']?
> Note that there are no spaces in the original string.
>Str.split() without any arguments looks for whitespace
> How do I split a string like "Hans" into a list of characters
> ['H','a','n','s']?
[snip]
well you could write your own function...
def splititems(itemlist):
templist = []
for item in itemlist:
templist.append(item)
return templist
print splititems("Hello")
or even
def
Hi,
A quick one...
How do I split a string like "Hans" into a list of characters
['H','a','n','s']?
Note that there are no spaces in the original string.
Str.split() without any arguments looks for whitespace as splitting
character. So, this doesn't serve the purpose.
And str.split("") app