frozenset.copy() does not create a copy
May 4, 2018
12:47 p.m.
Tried it in Python 2.7 and found that it just creates an alias to the original set.
May 8, 2018
8:28 a.m.
On Tue, May 8, 2018 at 5:20 PM Mihail Temelkov <mtemelkov@gmail.com> wrote:
Tried it in Python 2.7 and found that it just creates an alias to the original set.
In Python, copy() or similar methods may return itself for immutable types. It's widely used optimization.
t=(1,2) t1=(1,2) t2=t1[:] t1 is t2 True
And it is implementation (CPython) specific optimization; other implementation may return new instance. You shouldn't rely on undocumented behavior. Regards, -- INADA Naoki <songofacandy@gmail.com>
3044
Age (days ago)
3048
Last active (days ago)
1 comments
2 participants
participants (2)
-
INADA Naoki -
Mihail Temelkov