[Tutor] Working with strings

alan.gauld@bt.com alan.gauld@bt.com
Mon, 12 Mar 2001 18:21:05 -0000


------_=_NextPart_001_01C0AB21.33B2CC00
Content-type: text/plain; charset="iso-8859-1"

Doh!!!

The algorithm should I think be:
 
index = len(bruce)-1
while index >= 0:
    print bruce[index]
    index = index -1
 
Thus for 'flowerpot' we get an index of 8
which now enters the while loop
Now we can print bruce[-n](ie 't') 
 

bruce[index] not [-n]... where'd that come from?!!!
 
Alan G.

------_=_NextPart_001_01C0AB21.33B2CC00
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=330101518-12032001>Doh!!!</SPAN></FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV><SPAN class=780560318-12032001><FONT color=#0000ff face=Arial size=2>The 
  algorithm should I think be:</FONT></SPAN></DIV>
  <DIV><SPAN class=780560318-12032001></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=780560318-12032001></SPAN><FONT color=#0000ff 
  face="Courier New" size=2><SPAN class=780560318-12032001>index = 
  len(bruce)-1</SPAN></FONT></DIV>
  <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
  class=780560318-12032001>while index &gt;= 0:</SPAN></FONT></DIV>
  <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
  class=780560318-12032001>&nbsp;&nbsp;&nbsp; print 
  bruce[index]</SPAN></FONT></DIV>
  <DIV><FONT color=#0000ff face="Courier New" size=2><SPAN 
  class=780560318-12032001>&nbsp;&nbsp;&nbsp; index = index 
  -1</SPAN></FONT></DIV>
  <DIV><FONT color=#0000ff size=2><SPAN 
  class=780560318-12032001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>Thus 
  for 'flowerpot' we get an index of 8</SPAN></FONT></DIV>
  <DIV><FONT color=#0000ff face=Arial size=2><SPAN 
  class=780560318-12032001>which now enters the while loop</SPAN></FONT></DIV>
  <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=780560318-12032001>Now 
  we can print bruce[-n](ie 't') </SPAN></FONT></DIV>
  <DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN 
  class=780560318-12032001><SPAN 
  class=330101518-12032001>&nbsp;</SPAN></SPAN></FONT></FONT></FONT></DIV></BLOCKQUOTE>
<DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN 
class=780560318-12032001><SPAN class=330101518-12032001>bruce[index] not [-n]... 
where'd that come from?!!!</SPAN></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN 
class=780560318-12032001><SPAN 
class=330101518-12032001></SPAN></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face=Arial><SPAN 
class=780560318-12032001><SPAN class=330101518-12032001>Alan 
G.</SPAN></SPAN></FONT></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C0AB21.33B2CC00--