Which is faster? (if not b in m) or (if m.count(b) > 0)
Which is Faster in Python and Why?
jc = {}; m = []
x = [ [1,2,3,4,5,6,7,8,9],[..],...] # upwards of 1 entries
def mcountb():
for item in x:
b = item[:]; b.sort(); bc = 0
for bitem in b: bc += int(bitem)
try: m = jc[bc]
except: m = []
if m.count(b) == 0:
m.append(b); jc[bc]=m
def binm()
for item in x:
b = item[:]; b.sort(); bc = 0
for bitem in b: bc += int(bitem)
try: m = jc[bc]
except: m = []
if not b in m:
m.append(b); jc[bc]=m
--
http://mail.python.org/mailman/listinfo/python-list
Re: Which is faster? (if not b in m) or (if m.count(b) > 0)
Great observations... Changing for lists to tuples would make sorting unnecessary... -- http://mail.python.org/mailman/listinfo/python-list
Re: Which is faster? (if not b in m) or (if m.count(b) > 0)
Well, I could, but I was looking for answers from persons more experienced in the ways of Python then myself -- http://mail.python.org/mailman/listinfo/python-list
Re: Which is faster? (if not b in m) or (if m.count(b) > 0)
Tim, Are you saying that: not (b in m) is faster than: b not in m -- http://mail.python.org/mailman/listinfo/python-list
Re: Which is faster? (if not b in m) or (if m.count(b) > 0)
Execellent, Kent. Thank you... and everyone too! I've learned much! -- http://mail.python.org/mailman/listinfo/python-list
Re: Which is faster? (if not b in m) or (if m.count(b) > 0)
Thank you, Peter! Please understand, I was attempting to get more info on the WHY x is faster than y... from those with more experience. Timer cannot give me that info. -- http://mail.python.org/mailman/listinfo/python-list
