On Fri, Feb 12, 2016 at 2:13 PM, MRAB <pyt...@mrabarnett.plus.com> wrote: > Apart from all of the other answers that have been given: > >>>> p1 = 'foo/bar' >>>> p2 = 'foo/bar' >>>> id(p1), id(p2) > (982008930176, 982008930120) >>>> d = {} >>>> id(d.setdefault(p1, p1)) > 982008930176 >>>> id(d.setdefault(p2, p2)) > 982008930176 > > The dict maps equal strings (dirnames) to the same string, so you won't have > multiple copies.
Simpler to let the language do that for you: >>> import sys >>> p1 = sys.intern('foo/bar') >>> p2 = sys.intern('foo/bar') >>> id(p1), id(p2) (139621017266528, 139621017266528) ChrisA -- https://mail.python.org/mailman/listinfo/python-list