2 problems

Simon Forman rogue_pedro at yahoo.com
Fri Jul 7 21:41:45 EDT 2006


symonlandor at gmail.com wrote:
> Hello,Im using Python 2.4.2 and I'm starting a few very basic
> programs,but theres two problems I've not found the answers for.
> My first problem is I need code that will count the number of letters
> in a string and return that number to a variable.

Do you mean like this

>>> s = 'abracadabra'
>>> s.count('a')
5
>>> s.count('ab')
2

> My second problem stems from the first as I need a function that can
> slice the string into letters and have those put in seperate
> strings.Ive tried using the normal [:1],[:2],etc but I need a function
> that can do that a variable amount of times due to the varying number
> of letters in the input.

I'm sorry, but I don't know what you mean here.

>
> This would be of great help,as python is new to me.

It's a great language!

Peace,
~Simon




More information about the Python-list mailing list