Efficient way to add elements to a tuple
问题 I want to add elements to a tuple. I found 2 ways to do it. This and this answers say add two tuples. It will create a new tuple a = (1,2,3) b = a + (5,) Where as this says, convert the tuple to list, add the element and then convert it back to tuple a = (1,2,3) tmp = list(a) tmp.insert(3, 'foobar') b = tuple(tmp) Which among these two is efficient in terms of memory and performance? Also, suppose I want to insert an element in the middle of a tuple, is that possible using the first method?