how to mutate a tuple?

Carlo v. Dango oest at soetu.eu
Tue Oct 14 10:35:14 EDT 2003


On Tue, 14 Oct 2003 10:14:25 -0400, John Roth <newsgroups at jhrothjr.com> 
wrote:

>
> "Carlo v. Dango" <oest at soetu.eu> wrote in message
> news:oprw1cm4ytmyya52 at news.kadnet.dom...
>> On Tue, 14 Oct 2003 09:33:46 -0400, Roy Smith <roy at panix.com> wrote:
>>
>> Many thanks for your quick reply!
>>
>> aaaahh so there is a tuper() construct! :) that helps a lot.. still this
>> seems rather inefficient to create a list and then a new tuple.. but I
>> guess there really is no easier way.
>>
>> but is there a tuple=>list function ? so that instead of creating the 
>> list
>> by a for-construct I could just say
>>
>> list = tuple.tolist()
>> list[0] = newval
>> return turple(list)
>
> No. If you think about it, for such a method to work, it would have
> to change the object in place from a tuple to a list,


sorry, the code should have been:  mylist = mytuple.tolist()


> If you need to mutate a tuple, then I'd begin to question
> whether there isn't something else wrong with the design.

I do.. I'd rather pass around a list.. but as I said I'm using the *args 
mechanism in python which is a tuple and not a list.


-Carlo van Dango





More information about the Python-list mailing list