Suppose you have several ways to create objects with the string value "foo":
def f(s): return s.lower() li=['foo',
is only True if objects have the same id . You can check this and see which string objects were interned into the same immutable string at runtime:
def cat(l): d={} for i,e in enumerate(l): k=id(e) d.setdefault(k,[]).append(i) return '\n'.join(str((k,d[k])) for k in sorted(d))
Print
(4299781024, [0, 2, 3, 6, 7, 11, 12, 13, 15]) (4299781184, [5]) (4299781784, [1]) (4299781864, [4]) (4299781904, [9]) (4299782944, [8]) (4299783064, [10]) (4299783144, [14])
You can see that most solutions (or interned ones) refer to the same string objects, but some of them don't. It depends on the implementation.
You can make them the same string objects using the intern function:
print cat([intern(s) for s in li])
Print
(4299781024, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])