Fork me on GitHub

Jul 11, 2009

Hashes and Dicts in Python and Ruby

*dicts or hashes are passed by reference in Python and Ruby*

That's it!

Python example:


Output:

[{'a': 1}, {'a': 1}, {'a': 1}, {'a': 1}]

Ruby example:


Output:

[{"a"=>1}, {"a"=>1}, {"a"=>1}, {"a"=>1}]

3 comments:

Igor said...

No pretty output in Ruby... I have to work in my Ruby-jitsu :P

David Cuadrado said...

hi Igor,

to improve rubys example output you can do:

puts l.inspect

or

require 'pp'
...code...
pp l

Igor said...

done, thanks!

disclaimer



Things written in this blog are my personal thoughts or points of view, and do not represent at all the position of my employer.

Code in the website is licensed under The MIT License

Content of this blog is:
Creative Commons License
Licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.