d.keys() and d.values()

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

  1. Gerrit Holl

    Gerrit Holl Guest

    Hi,

    is it guaranteed that dict(zip(d.keys(), d.values())) == d?
    In words, do .keys() and .values() always have the same order? Is
    it safe to rely on this?

    yours,
    Gerrit.

    --
    279. If any one by a male or female slave, and a third party claim it,
    the seller is liable for the claim.
    -- 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 24, 2003
    #1
    1. Advertising

  2. Gerrit Holl

    Max M Guest

    Gerrit Holl wrote:
    > Hi,
    >
    > is it guaranteed that dict(zip(d.keys(), d.values())) == d?
    > In words, do .keys() and .values() always have the same order? Is
    > it safe to rely on this?


    It says so in the docs.

    http://www.python.org/doc/current/lib/typesmapping.html

    (3) "Keys and values are listed in random order. If keys() and values()
    are called with no intervening modifications to the dictionary, the two
    lists will directly correspond. This allows the creation of (value, key)
    pairs using zip(): "pairs = zip(a.values(), a.keys())". "


    regards Max M
    Max M, Jun 24, 2003
    #2
    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. sandeep Kanwal

    serial keys/validation keys

    sandeep Kanwal, Oct 29, 2004, in forum: C++
    Replies:
    1
    Views:
    583
    Mike Wahler
    Oct 29, 2004
  2. Harry George
    Replies:
    9
    Views:
    701
    sonal
    Jun 13, 2006
  3. Replies:
    10
    Views:
    724
    Daniel T.
    Feb 3, 2006
  4. alan
    Replies:
    3
    Views:
    363
    Victor Bazarov
    Nov 28, 2007
  5. A. Farber
    Replies:
    10
    Views:
    237
    A. Farber
    Jun 12, 2004
Loading...

Share This Page