TypeError: 'tuple' object does not support item assignment when swapping values
Evaluating "1,2,3" results in (1, 2, 3)
, a tuple
. As you've discovered, tuples are immutable. Convert to a list before processing.
or simply assign the whole tuple itself, instead of changing elements inside tuple.
example: want to add 'count' to 1st element of the 'i-th' tuple :
tup[i] = (tup[i][0] + count, tup[i][1])