jcayzac
jcayzac

Reputation: 1461

Pre-hashed string keys for faster Python dictionaries lookup?

How can I instruct python to store, internally, a pre-hashed version of my strings, so that it will use that value when I perform dict/set lookups using my string as a key?

I remember reading about it some weeks ago, but can't find it in python docs at the moment :-/

Upvotes: 9

Views: 1102

Answers (1)

Glenn Maynard
Glenn Maynard

Reputation: 57474

String interning is probably what you're thinking of.

See sys.intern in Python 3

See intern in Python 2

Upvotes: 3

Related Questions