Typeerror: 'tuple' Object Does Not Support Item Assignment When Swapping Values
I am writing a simple sort program in python and encounter this error. I want to swap list elements but it returns an error. I am attaching the error and program in question below.
Solution 1:
Evaluating "1,2,3" results in (1, 2, 3)
, a tuple
. As you've discovered, tuples are immutable. Convert to a list before processing.
Solution 2:
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])
Solution 3:
To anyone googling this error: check for unwanted commas in your code. For example,
arr = np.zeros(n),
arr[i] = something
will throw this error.
Post a Comment for "Typeerror: 'tuple' Object Does Not Support Item Assignment When Swapping Values"