When to use list and tuples?.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • psbasha
    Contributor
    • Feb 2007
    • 440

    #1

    When to use list and tuples?.

    Hi,

    I know that list and dict are mutable and tuples are immutables.But list and tuples do the similar datastorage with different representation

    But how to decide when to use list and tuples?.

    Can anybody suggest this scenario.

    Thanks in advance
    PSB
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by psbasha
    Hi,

    I know that list and dict are mutable and tuples are immutables.But list and tuples do the similar datastorage with different representation

    But how to decide when to use list and tuples?.

    Can anybody suggest this scenario.

    Thanks in advance
    PSB
    This gets us into the discussion of mutable vs immutable objects.
    For "constant" lists, like a list of functions in a lookup table, it is more effecient to use a tuple. Tuples don't allow assignment:
    Code:
    >>> t = (1, 2, 3,)
    >>> t[1] = 5
      File "<console>", line 1, in ?
    ''' exceptions.TypeError : object does not support item assignment '''
    >>>
    Tuples are also more picky about integer type indexes than lists:
    Code:
    >>> l = ["no", "yes"]
    >>> l[True]
    'yes'
    >>>
    doesn't work with tuples.

    Comment

    • psbasha
      Contributor
      • Feb 2007
      • 440

      #3
      Thanks for the reply.

      I would like to know more about the "list of functions in a lookup table".Is it possible to get any links or material for this.


      -PSB

      Comment

      • Extremist
        New Member
        • Jan 2007
        • 94

        #4
        Originally posted by psbasha
        Thanks for the reply.

        I would like to know more about the "list of functions in a lookup table".Is it possible to get any links or material for this.


        -PSB
        Google, Search, get creative

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by psbasha
          Thanks for the reply.

          I would like to know more about the "list of functions in a lookup table".Is it possible to get any links or material for this.


          -PSB
          You could try reading the relplies to your other posts. This is the reason for keeping threads on a topic going on that topic rather than starting a new thread.

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by bartonc
            You could try reading the relplies to your other posts. This is the reason for keeping threads on a topic going on that topic rather than starting a new thread.
            I am refering, of course, to this thread.

            Comment

            Working...