Moving around in a string

Ryan Spencer jeder at earthlink.net
Sat Dec 6 13:50:45 EST 2003


On Sat, 06 Dec 2003 08:18:00 -0600, Mark Engle wrote:

> Peter Otten wrote:
> 
>> Mark Engle wrote:
>> > http://www.python.org/doc/current/lib/module-string.html
>> > 
>> 
>> One caveat (only for the string module), quoting from the above
>> document, but easily overlooked:
>> 
>> "Many of the functions provided by this module are also defined as
>> methods of string and Unicode objects; see ``String Methods''
>> (section 2.2.6) for more information on those." 
>> 
>> So whenever you're tempted to write string.somefunc(s, moreargs),
>> rather use s.somefunc(moreargs).
>> 
>> Peter
> 
> Thank you.  Time to do some more reading.
> 
> Mark

Hello Everyone, 

	I pulled it off. Thank you for the direction of the split function, Mark.

[start code]

words_within = sentence.split()

word_count = 0 

for i in words_within:
	word_count = word_count+1

print "There are", word_count, "words."

[end code]

Haha, Now that I've got my parsing fun over with, I can head back to my
translation. All I need to figure out now is how to apply the code

[start code]

pig_latin = word[1:]+word[0]+"ay"

[end code]

to each word in the string. Any advice on what I should do would be
appreciated. 

Thanks,

~Ryan




More information about the Python-list mailing list