Re: lists and tuples

Discussion in 'Python' started by Gerrit Holl, Jun 28, 2003.

  1. Gerrit Holl

    Gerrit Holl Guest

    John Hunter wrote:
    > Gerrit> I don't understand. I really don't understand.
    >
    > For me, the most important distinction is that because lists are
    > mutable, they cannot be used as keys in a dictionary.


    This is probably a basic question, but I can't see why mutable
    objects can't be used as dictionairy keys. Why would this be
    impossible:

    0 >>> d = {}
    1 >>> l = []
    2 >>> d[l] = "foo"
    3 >>> d
    {[]: 'foo'}
    4 >>> l.append("bar")
    5 >>> l
    ['bar']
    6 >>> d
    {['bar']: 'foo'}

    What is the problem of doing this?

    yours,
    Gerrit.

    --
    59. If any man, without the knowledge of the owner of a garden, fell a
    tree in a garden he shall pay half a mina in money.
    -- 1780 BC, Hammurabi, Code of Law
    --
    Asperger Syndroom - een persoonlijke benadering:
    http://people.nl.linux.org/~gerrit/
    Het zijn tijden om je zelf met politiek te bemoeien:
    http://www.sp.nl/
     
    Gerrit Holl, Jun 28, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Nogradi
    Replies:
    3
    Views:
    373
    Dennis Lee Bieber
    Nov 10, 2006
  2. Replies:
    5
    Views:
    582
    Thomas J. Gritzan
    Oct 6, 2006
  3. tuples within tuples

    , Oct 26, 2007, in forum: Python
    Replies:
    12
    Views:
    621
    Dennis Lee Bieber
    Oct 27, 2007
  4. xera121
    Replies:
    8
    Views:
    764
    lolmc
    Sep 30, 2009
  5. Jon Reyes
    Replies:
    18
    Views:
    276
    Mitya Sirenef
    Feb 19, 2013
Loading...

Share This Page