HNHacker News
TopNewBestAskShowJobs

octopope

4 karma · joined June 14, 2018

submissionscomments
octopope··on Optimization tricks in Python: lists and tuples
Ahh.. interesting. Then I guess using the id of the tuples to show that they are using the same object doesn't exactly prove the point.

To your original point (that tuples reallocate based on length) I see that if I delete a tuple of length 3 and then create a tuple of length 5 I see the id is immediately changed. So that's correct.

Lists on the other hand seem to keep reallocating the same address in my limited test.

Strings seem to behave like tuples. When I delete a string and create a new one it creates a new object with a new address.... unless the strings are of the same length.

Perhaps this is no real revelation, I'm rather new to python and spending my time poking around to see how it works. :)

octopope··on Optimization tricks in Python: lists and tuples
The free list for lists seems to reuse more than just empty lists as you suggest.

  > a = ['non','empty','list']
  > id(a)
  4363176072
  > del a
  > b = ['new', 'list']
  > id(b)
  4363176072