any() and all() on empty list?

Ron Adam rrr at ronadam.com
Thu Mar 30 12:23:29 CEST 2006


Duncan Booth wrote:
> Ron Adam wrote:
> 
>> Where we are assembling widgets in a manufacturing plant. Where we don't 
>> want to go to the next step until *all* the sub parts are present.
>>
>> if all(part.status == 'present' for part in unit):
>>      do_release()
>>
>> Oops!  Some empty bins showed up at the next assembly station. ;-)
> 
> I don't see the problem. You only get an empty bin if there is some part 
> assembled from no sub-parts, in which case you wanted an empty bin.

Hmmm...  It wasn't a well though out example.  I was thinking in terms 
of several processes working at the same time, and not communicating 
with each other.  Ie.. a bin getter, a part inserter, a part checker, a 
bin mover. etc.

But even then if all the parts get marked as 'present' even though they 
are aren't there, the bin could be released to the next station.  And so 
that example is void.  I'll try and think of a better one.


Cheers,
    Ron




More information about the Python-list mailing list