View Single Post
Old Nov 25th, 2005, 3:37 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,869
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Your all/any function could be easily generalised and used in more contexts like so:

def get_instances(list, instance):
    i = 0
    for item in list: i += item==instance
    return i

print get_instances( [0, 1, False, True], True )

As well, that "any" function can be summarized in a simple condition:

if True in list: print "At least one true is in the list."
(and same to your "all" function: if False in list)

Nice Cache function though.

Last edited by Sane; Nov 25th, 2005 at 3:53 PM.
Sane is offline   Reply With Quote