Issue1775893

classification
Title: in keyword does not use dict.has_key()
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: codepage, pjenvey
Priority: high Keywords:

Created on 2007-08-16.21:44:33 by codepage, last changed 2007-09-13.02:26:33 by pjenvey.

Messages
msg1845 (view) Author: Mr. Codepage (codepage) Date: 2007-08-16.21:44:33
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 ]
msg1846 (view) Author: Philip Jenvey (pjenvey) Date: 2007-09-13.02:26:33
fixed in r3473, thanks!
History
Date User Action Args
2007-08-16 21:44:33codepagecreate