On Mar 22, 3:32 pm, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > On 21 mar, 19:25, John Machin <[EMAIL PROTECTED]> wrote: > > > > > On Mar 22, 8:51 am, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > > > > If you drop this condition then you could fill the array with zeroes > > > as before, replace only the interesting ones with actual functions, > > > and write: > > > > for item in myarray[nonzero(myarray)]: > > > print item() if callable(item) else item > > > Let's unbuckle the seat belt :-) > > > If "item" is definitely restricted to being either 0 or a callable > > object, then > > item() if item else 0 > > should give the same answer as, and is quite likely to be faster than, > > item() if callable(item) else item > > as it avoids a global lookup and a function call. > > In that case, we could use a bare item() because nonzero would have > filtered out all that zeroes.
True. -- http://mail.python.org/mailman/listinfo/python-list