Hash#keys, Hash#values order question

Discussion in 'Ruby' started by Ronald Fischer, Aug 23, 2007.

  1. Let h be a Hash. Calculating the arrays

    k=3Dh.keys
    v=3Dh.values

    under the assumption that h is not modified
    in between, is it guaranteed that for all
    indices n

    h[k[n]]=3D=3Dv[n]

    i.e. that Hash#values delivers the values
    in the same order than Hash#keys delivers
    the respective keys?

    When playing around, I found this always
    the case, but can I rely on it?

    Ronald
    --=20
    Ronald Fischer <>
    Phone: +49-89-452133-162
    Ronald Fischer, Aug 23, 2007
    #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. Menghan Zheng
    Replies:
    1
    Views:
    270
    alex23
    Apr 20, 2010
  2. Cameron Simpson
    Replies:
    6
    Views:
    351
    alex23
    Apr 21, 2010
  3. Alex Fenton

    Hash#values and Hash#keys order

    Alex Fenton, Apr 7, 2006, in forum: Ruby
    Replies:
    1
    Views:
    138
    George Ogata
    Apr 15, 2006
  4. Mage

    hash.keys and hash.values

    Mage, Aug 13, 2006, in forum: Ruby
    Replies:
    14
    Views:
    176
  5. Hemant Shah
    Replies:
    7
    Views:
    121
    Hemant Shah
    Jan 9, 2004
Loading...

Share This Page