Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to mutate a tuple?

Reply
Thread Tools

how to mutate a tuple?

 
 
John Roth
Guest
Posts: n/a
 
      10-14-2003

"Carlo v. Dango" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> On Tue, 14 Oct 2003 10:14:25 -0400, John Roth <(E-Mail Removed)>
> wrote:
>
> >
> > "Carlo v. Dango" <(E-Mail Removed)> wrote in message
> > news(E-Mail Removed)...
> >> On Tue, 14 Oct 2003 09:33:46 -0400, Roy Smith <(E-Mail Removed)> 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()


Ah. That's not a bad idea. Mostly it's a language
design decision. object.toSomeOtherType() designs put the
responsibility for converting on the 'from' object, languages
that overload their constructors (like Python) put the responsibility
on the 'to' object. Neither one is clearly better since neither one
gracefully handles the question of what to do when you add a new
type: there are always places where you can't easily add the
needed glue.

Python has chosen to go down the path of haveing one obviously
'right' way to do most tasks (as distinct from Perl, whose motto is
"there's more than one way to do it",) and it's chosen to put the
responsibility for type conversion on the constructor of the new type.

John Roth


>
>
> > 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
pygene, mutate jenik General Computer Support 0 12-12-2010 10:09 PM
Re: mutate dictionary or list Bruno Desthuilliers Python 0 09-07-2010 01:55 PM
mutate an object or create a new one? toton Java 23 11-02-2006 01:37 PM
naming convention for functions that mutate their arguments? mike p. Python 1 02-27-2004 02:18 AM



Advertisments