for statement on empty iterable

james_027 cai.haibin at
Wed Aug 22 08:49:32 CEST 2007


> Oh I see.  You have to combine a couple of concepts but for this
> example you'd say:
>    name = 'james'     # 'l' looks too much like the digit 1
>    for i,c in enumerate(name):
>       print i, c
>    print i
> enumerate(name) generates the sequence
>    (0,'j'), (1,'a'), (2,'m'), (3,'e'), (4,'s')
> and the above loop splits those tuples into two indexes i and c.
> You should probably read the tutorial and work through the examples.
> If you get something wrong with this basic stuff, your computer won't
> explode or anything like that, so try stuff out.  Be more careful when
> you start using library routines that can delete files ;).

Thanks, it just that I am afraid of coding that something works but
ugly or inefficient.


More information about the Python-list mailing list