From: SourceForge.net <no...@so...> - 2007-08-16 21:50:23
|
Bugs item #1775893, was opened at 2007-08-16 14:44 Message generated for change (Settings changed) made by codepage You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1775893&group_id=12867 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Core Group: targeted for 2.2rc3 Status: Open Resolution: None >Priority: 6 Private: No Submitted By: Mr. Codepage (codepage) Assigned to: Nobody/Anonymous (nobody) >Summary: in keyword does not use dict.has_key() Initial Comment: When checking to see if an element is contained in a dict as in if foo in bar_dict: do_stuff() Jython is not using bar_dict.has_key(foo) to check for existence at least that is what it looks like. When the code below is run in cpython each block returns the same results in about the same time. When run under jython, the last section will pretty much put the program to sleep. nap time. It might be an easy fix, just noting it here. Use has_key() instead of in for now. __doc__ = """ given two lists, return the elements that are in one and not the other not in <object> when object is a dict doesn't appear to use the has_key() method """ a = range(100000) a_map = {} def s(m,v): # set key v on m to 1 m[v]=1 b = range(99980) b_map = {} [ s(b_map,x) for x in b ] print "this is fast in jython, fractions of a second" not_in = [] for x in a: if b_map.has_key(x): continue else: not_in.append(x) print not_in print "comprehension is also quick" print [ x for x in a if not b_map.has_key(x) ] print "jython will take forever to do this" print [ x for x in a if x not in b_map ] ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1775893&group_id=12867 |