[Tutor] a little loop
Tim Hanson
tjhanson at yahoo.com
Tue May 28 05:54:58 CEST 2013
Okay, so I made it to FOR loops in the Lutz book. A couple of days ago I was
helped here with the .join method for creating strings from lists or tuples of
strings. I got to wondering if I could just, for the sake of learning, do the
same thing in a FOR loop, since that's today's chapter:
x=0; ham=''; b=['s','p','a','m'] #or, b=('s','p','a','m')
for t in b:
ham=ham+b[x]
print(ham);x+=1
s
sp
spa
spam
Alright, it works, eventually. Can someone help me find a little more elegant
way of doing this? I'm sure there are several.
Incidentally, I put the print statement within the FOR loop so I could watch
progress.
More information about the Tutor
mailing list