Re: for statement on empty iterable

2007-08-22 Thread J. Cliff Dyer
Neil Cerutti wrote: On 2007-08-22, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: While it is desireable to not only write working, but also aesthetically pleasing code, as a beginner you shouldn't worry too much. The sense of aesthetics develops with time. Important is to try and grasp the idio

Re: for statement on empty iterable

2007-08-22 Thread Neil Cerutti
On 2007-08-22, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > While it is desireable to not only write working, but also > aesthetically pleasing code, as a beginner you shouldn't worry > too much. The sense of aesthetics develops with time. Important > is to try and grasp the idioms of the language

Re: for statement on empty iterable

2007-08-22 Thread Steve Holden
Amit Khemka wrote: > On 8/22/07, james_027 <[EMAIL PROTECTED]> wrote: >> hi Paul, >> >>> That doesn't crash or anything like that, but it also doesn't >>> set the index variable, which can cause confusion in some situations. >> Thanks for your quick answer ... Actually I was thinking how do I >> ac

Re: for statement on empty iterable

2007-08-22 Thread Eric Abrahamsen
Here's another simple method: l = ['j', 'a', 'm', 'e', 's'] counter = 0 for i in l: # Do your code counter += 1 print counter Yrs, Eric > l = ['j', 'a', 'm', 'e', 's'] > > for i in l > # i want to know the nth number of times it has loop thru or > something like counter? > > Thanks

Re: for statement on empty iterable

2007-08-22 Thread Diez B. Roggisch
james_027 schrieb: > hi, > >> 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 >>

Re: for statement on empty iterable

2007-08-21 Thread james_027
hi, > 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'),

Re: for statement on empty iterable

2007-08-21 Thread Paul Rubin
james_027 <[EMAIL PROTECTED]> writes: > Yes i am new to python :). I am sorry I should be clarify myself ... > for example > > l = ['j', 'a', 'm', 'e', 's'] > > for i in l > # i want to know the nth number of times it has loop thru or > something like counter? Oh I see. You have to combine a c

Re: for statement on empty iterable

2007-08-21 Thread Amit Khemka
On 8/22/07, james_027 <[EMAIL PROTECTED]> wrote: > hi Paul, > > > > > That doesn't crash or anything like that, but it also doesn't > > set the index variable, which can cause confusion in some situations. > > Thanks for your quick answer ... Actually I was thinking how do I > access the index insi

Re: for statement on empty iterable

2007-08-21 Thread james_027
hi, > It sounds like you're just starting to learn the language... have you > read the online tutorial yet? That is a pretty easy introduction. > > See:http://python.org/doc/ > > Anyway, you can say > >for i in (1,2,3): > print i*5 > > to print 5, 10, and 15 on separate lines, for examp

Re: for statement on empty iterable

2007-08-21 Thread Paul Rubin
james_027 <[EMAIL PROTECTED]> writes: > Thanks for your quick answer ... Actually I was thinking how do I > access the index inside a for statement? Can you help It sounds like you're just starting to learn the language... have you read the online tutorial yet? That is a pretty easy introduction.

Re: for statement on empty iterable

2007-08-21 Thread james_027
hi Paul, > > That doesn't crash or anything like that, but it also doesn't > set the index variable, which can cause confusion in some situations. Thanks for your quick answer ... Actually I was thinking how do I access the index inside a for statement? Can you help Thanks james -- http://mai

Re: for statement on empty iterable

2007-08-21 Thread Paul Rubin
james_027 <[EMAIL PROTECTED]> writes: > for i in []: > #do something > is this safe? or should I put a if statement to test it first? That doesn't crash or anything like that, but it also doesn't set the index variable, which can cause confusion in some situations. -- http://mail.python.org/mail

for statement on empty iterable

2007-08-21 Thread james_027
hi, I need to do some for loop on iterables which could be empty sometimes, for example a_list = [] for i in a_list: #do something is this safe? or should I put a if statement to test it first? Thanks james -- http://mail.python.org/mailman/listinfo/python-list