On Mar 23, 5:45 pm, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > John Nagle <[EMAIL PROTECTED]> writes: > > What's the cheapest way to test for an empty dictionary in Python? > > > if len(dict.keys() > 0) : > > I like to think len(dict) is constant time but I haven't checked the code. > Same for bool(dict) (which is what you get when you run "if dict: ...").
It has to be constant time as it is a lower bound for inserts (which average to constant time). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list