Add a "replace" method to tuples that returns a new tuple with the element at a 
given index replaced with a given value. Example implementation:

def replace(self, index, value):
return self[:index] + (value,) + self[index + 1:]

See 
https://stackoverflow.com/questions/11458239/how-to-change-values-in-a-tuple 
for more context.

Currently, tuples have 2 public methods: index and count. replace would be 
similarly easy to implement and similarly useful.

Furthermore, it would be a natural counterpart to nametuple's _replace method.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/TIHIG74ADMMZRKRNGR2TDZSXIMM6N7JM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to