octopope
Re:Optimization tricks in Python: lists and tuples
on Thursday June 14, 2018 @02:30PM (#17314113)
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. :)
Re:Optimization tricks in Python: lists and tuples
on Thursday June 14, 2018 @01:43PM (#17313610)
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