Moving around in a string

Ryan Spencer jeder at earthlink.net
Sat Dec 6 05:07:32 EST 2003


On Sat, 06 Dec 2003 09:13:53 +0000, Troels Therkelsen wrote:

> This sounds suspiciously like homework, but...
> 
>>>> foo = "Orange"
>>>> bar = foo[1:] + foo[0] + 'ay'
>>>> bar
> 'rangeOay'
> 
> In other words, you can index strings the same way as any other sequence,
> [0] is the first element of the sequence, [1] the second, [-1] is the last,
> and so forth.
> 
> See also the standard documentation on sequences:
> 
>     http://www.python.org/doc/current/lib/typesseq.html
> 
> 
> Regards,
> 
> Troels Therkelsen

Hey Troels,

	Thanks for the advice, Pulled it off by.

[start code]

def pig_latin(word):

	space = word[0]

	result = word[1:]+space+"ay"
	print result

[end code]

This all leads me to another problem. In my recent attempts I've
been trying to learn how to parse sentences and such down more and more
(by amt. of characters, words, lines, etc.) If you don't mind another
question, how do I go about say, parsing for words in a string?

I would logically conclude to somehow find a way to declare that
everything with a space between it (or for every space) add one to a
'word_count' variable maybe, but, the question for that would be how do I
get the system to search the string for a certain character, especially if
it is a space?

Thanks a ton,

~Ryan




More information about the Python-list mailing list