# Ruby lookups(=python dict)?

**URL:** <https://www.ruby-forum.com/t/ruby-lookups-python-dict/138709>\
**Category:** Ruby\
**Created:** [May 27, 2008, 3:45am UTC](https://www.ruby-forum.com/t/ruby-lookups-python-dict/138709 "2008-05-27T03:45:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 27, 2008, 3:45am UTC](https://www.ruby-forum.com/t/ruby-lookups-python-dict/138709/1 "2008-05-27T03:45:47Z")

</div>

what is the easiest way for a dict like in python?

are there hash tables?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 27, 2008, 3:49am UTC](https://www.ruby-forum.com/t/ruby-lookups-python-dict/138709/2 "2008-05-27T03:49:18Z")

</div>

On May 26, 2008, at 7:44 PM, removed\_email\_address@domain.invalid wrote:

> what is the easiest way for a dict like in python?
> 
> are there hash tables?

gen install orderedhash

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 27, 2008, 3:58am UTC](https://www.ruby-forum.com/t/ruby-lookups-python-dict/138709/3 "2008-05-27T03:58:40Z")

</div>

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# what is the easiest way for a dict like in python?

# are there hash tables?

yes.

qri Hash

or

[http://www.ruby-doc.org/core/classes/Hash.html](http://www.ruby-doc.org/core/classes/Hash.html)

in ruby1.9, insertion order is preserved.

kind regards -botp

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 27, 2008, 4:01am UTC](https://www.ruby-forum.com/t/ruby-lookups-python-dict/138709/4 "2008-05-27T04:01:00Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

ara.t.howard wrote:

| gen install orderedhash  
~ ^^^  
Should be ‘gem’. 😉

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)  
Blog: [http://justarubyist.blogspot.com](http://justarubyist.blogspot.com)

Make sure input cannot violate the limits of the program.  
~ - The Elements of Programming Style (Kernighan & Plaugher)  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkg7ayYACgkQbtAgaoJTgL+pgQCfRBr4qrgVY3jS5xzi9441zE57  
ZX4AoKN2xXGZBx/jv2et/p+Hz4XE9VDv  
=chyJ  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 27, 2008, 1:24pm UTC](https://www.ruby-forum.com/t/ruby-lookups-python-dict/138709/5 "2008-05-27T13:24:36Z")

</div>

unknown wrote:

> what is the easiest way for a dict like in python?
> 
> are there hash tables?

The easiest solution is to use a hash, which is built into the language.  
This is assuming the order in which the entries are stored within the  
hash is unimportant. In very many cases this is true.

dict = {}  
dict[“aardvark”] = “a”  
dict[“badger”] = “b”  
p dict

You don’t have to use strings for keys and values; you can use just  
about anything you want.
