Here are a couple of things to look at. You could take the phrase and separate it into a list of words using split()
- >>> p='this is a phrase'
-
>>> p.split()
-
['this', 'is', 'a', 'phrase']
Then you could use a
for loop to pull out the first letter of each word. Remember that the first letter of a string has an index of 0, second is 1, etc.
- >>> for w in p.split():
-
... print w[0]
-
...
-
t
-
i
-
a
-
p
In this example I just printed the letter, but you could build a new word out of it (lets use
a for acronym)
- >>> a=''
-
>>> for w in p.split():
-
... a=a+w[0]
-
...
-
>>> print a
-
tiap
or if you wanted it all upper case
Some of these methods have been listed as deprecated in the python docs, which I don't study enough to know why. Could someone say where to look for the new methods, I understand that things like string.atof() became float() which makes sense to me. However I don't understand how to replace some of the others listed at http://docs.python.org/lib/node42.html. In this post I use string.upper(), what would be correct?