I'm trying to make a list which is used throughout the application immutable. I thought wrapping this list in a tuple would do the trick, but it seems that tuple(list)
doesn't actually wrap, but copies the list elements.
>>> a = [1, 2, 3, 4]
>>> b = tuple(a)
>>> b
(1, 2, 3, 4)
>>> a[0] = 2
>>> b # was hoping b[0] to be 2
(1, 2, 3, 4)
Is there an easy way of creating a list-backed "view" on this list that is immutable (wrt. operations on this view), but reflects any change that happened to the backing list?
I realise that this question has been asked before, but none of the responses address this view-backing list relationship (in fact some of the comments even suggest that tuples work the way I was hoping they do, but the above snippet suggests otherwise).