[Tutor] a little loop

kartik sundarajan kartiksundarajan at gmail.com
Tue May 28 06:28:04 CEST 2013


One way I can suggest is

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
>
>
> 't' is actually  equal to b[x] and its faster then indexed based look-up.
so you can rewrite

ham = ham + b[x]

as

ham += t

and remove the x increment.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130528/c2dafda6/attachment.html>


More information about the Tutor mailing list