<div dir="ltr"><div><div><div><div><br></div><div>Some other tools, if you haven't come across them yet.<br></div><br><div>You already know about str.join ()<br></div><div><br></div>Slicing <br><br> >>>b=['s','p','a','m'] <br>
</div>b [ : 1 ] <br><div>['s']<br>b [ : 2 ] <br>
['s', 'p']<br></div><br>Also, consider<br><br></div>>>>len ( b) <br>4<br><br></div>>>>range ( 4 )<br><div>[ 0, 1, 2, 3, 4]<br></div><div># which I can iterate over.<br></div><br><div><br>
</div><div><br><br><br><br><div><div><br><br><br><br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 28, 2013 at 4:54 AM, Tim Hanson <span dir="ltr"><<a href="mailto:tjhanson@yahoo.com" target="_blank">tjhanson@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Okay, so I made it to FOR loops in the Lutz book.  A couple of days ago I was<br>
helped here with the .join method for creating strings from lists or tuples of<br>
strings.  I got to wondering if I could just, for the sake of learning, do the<br>
same thing in a FOR loop, since that's today's chapter:<br>
<br>
x=0; ham=''; b=['s','p','a','m'] #or, b=('s','p','a','m')<br>
for t in b:<br>
        ham=ham+b[x]<br>
        print(ham);x+=1<br>
<br>
<br>
s<br>
sp<br>
spa<br>
spam<br>
<br>
Alright, it works, eventually.  Can someone help me find a little more elegant<br>
way of doing this?  I'm sure there are several.<br>
<br>
Incidentally, I put the print statement within the FOR loop so I could watch<br>
progress.<br>
_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</blockquote></div><br></div>