在Python中,如何通过赋值改变元组中的值?

In Python, how to change the values in a tuple by assignment?

我在列表的列表中有一些值看起来像这个元组

print list_of_lists[0][0]

(1,2,'.')

我想更改“.”到 '+' 或 '-' 以便它根据某些条件变为 (1,2,'+')

目前我做一个简单的 list_of_lists[0][0][2] = '+' 我得到一个错误: TypeError: 'tuple' object does not support item assignment 因为元组在 Python.

中是不可变的

我该怎么办?

试试这个(不是一个好的解决方案)

>>>list_of_lists = [[(1, 2, '.')]]
>>>[[tuple(["+" if j=="." else j for j in i]) if '.' in i else i for i in list_of_lists[0]]]
[[(1, 2, '+')]]