[BangPypers] An interesting beginner post at Stackoverflow

Sidharth Kuruvila sidharth.kuruvila at gmail.com
Wed Oct 21 09:44:13 CEST 2009

  My bad, that was a bit of laziness on my part. The reason why my
code was silly is not to do with interning though that does happen for
strings. Literals, that is numbers and string literals and a few
others are loaded as constants. So the cost of constructing them in
your code has already been taken care of.

A better example would be something like

d = {"a":[1,2,3,4]}

print d.setdefault("a", [])

Interning is an optimization done to speed up the comparison of
strings, by making sure that two string with the same text are
represented by the same object.


On Wed, Oct 21, 2009 at 12:31 PM, Anand Chitipothu <anandology at gmail.com> wrote:
>> What do you mean when you use the word "interned"?
> $ pydoc intern
> Help on built-in function intern in module __builtin__:
> intern(...)
>    intern(string) -> string
>    ``Intern'' the given string.  This enters the string in the (global)
>    table of interned strings whose purpose is to speed up dictionary lookups.
>    Return the string itself or the previously interned string object with the
>    same value.
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers

I am but a man.

More information about the BangPypers mailing list