Op 2005-02-05, Nick Coghlan schreef <[EMAIL PROTECTED]>: > [ ... ] > > With a rebinding operator, the intent of the last line can be made explicit: > > def collapse(iterable): > it = iter(iterable) > lastitem = it.next() > yield lastitem > for item in it: > if item != lastitem: > yield item > lastitem .= item > > (Note that doing this *will* slow the code down, though, since it has to > check > for the existence of the name before rebinding it)
I think that most of the time it won't slow down the code as the checking will have been done during the compilation phase. It may even speed up code like this, because the compilation phase will have established that it is a rebinding and so code for testing whether a new variable is created or not is not necessarry here. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list