From: john_sips_tea@... Date: 2006-03-27T07:43:54+09:00 Subject: Re: deciphering poignant guide chapter 4 example > First, let me warn you that from what you describe, you have > a Python viewpoint on the data structures and that it is quite > different from many many languages. Well, hopefully you folks can help straighten me out then. :) I've actually programmed in C, C++, Java, Perl, and Python, but my trouble is that as soon as I learn the next language, my brain tries to file previous language knowledge into my grey matter's round filing cabinet. :) > As you seem to come from the Python's world, you probably > know that Python's strings are immutable. And if you read a > little bit about why strings in Python are immutable, you will > see it's because they wanted to optimize the method lookup. I'll have to think about that. I don't see the connection between strings and method lookup. In Python code, you write a name(), and python works its way up the inheritance tree looking for the function definition. You can't call a method like: def my_func(): print "hi" foo = "my_func" foo() # Trying to call my_func, but it fails. so I don't see the string/method-call connection you're referring to... > In the end, Python's string are what's called in Ruby Symbol > and Ruby's strings have no equivalent in Python, as Python > has no mutable string class. Ah! Thanks. > You can expand it like that : > > sorted_kitty = kitty_toys.sort_by { |toy| toy[:shape] } > sorted_kitty.each do |toy| > [...] > end Got it. > The ruby equivalent of your python code would be : > > (1...8).each { |i| (1...4).each { |j| puts i,j} } Ah. Sweet. Thanks for throwing that in. :)