1

Python has a default searching function which is:

x in [x,y,z,]

Where x,y,z can be any integers or characters, but this is a default sequential search and I want to know how I can use a manual hashing search in python.

1
  • "[x if x.getHashKeyMethod()==y.getHashKeyMethod() for x in myIterable]" will return all the objects with same hash as y from myIterable, is that it? Commented Apr 19, 2013 at 16:00

1 Answer 1

4

Use a set() instead:

x in {x,y,z}

This uses a hash table under the hood, so searches are O(1).

Sign up to request clarification or add additional context in comments.

4 Comments

hmmm, is this another built-in python function?
Yes, I linked you to the documentation for sets. Sets are a standard type.
Whoa, I just learned about the {1,2,3} notation for sets. Has it always been there? I must have missed it...
It is new in Python 2.7 and 3.x.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.