Moving around in a string

Mark Engle engSpideRlem at pdxThiS.edu
Sat Dec 6 12:08:02 CET 2003


Ryan Spencer wrote:

> 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

I'm also new to Python, but I think I can point you in the right
direction.  Look into split() in library documentation.

http://www.python.org/doc/current/lib/module-string.html

The library documentation is a _very_ good reference.  Read that
whole page and you will find bunches of useful information.  I
found it to be very clear.

Mark




More information about the Python-list mailing list