4 ms·
I've programmed in Ruby for 6 years or so and this is my second year in Python. I think the Python function is more clear: Its obvious you will end up with an
by justinzollars 10y ago
I've programmed in Ruby for 6 years or so and this is my second year in Python.
I think the Python function is more clear:
Its obvious you will end up with an Array (List), and its iteration is more readable - "function of x for x in array"
- pmontra 10y agoIt's not the Ruby way, much like it won't be pythonic doing like Ruby does. It won't be as clear in Ruby, hence my initial difficulties with the pythonic form despite being similar to the standard mathematical notation. Ruby has methods, not functions. We call methods of Enumerable to transform list like objects (anything that includes Enumerable) and return another list like object to apply other methods to. And there is also Enumerable::Lazy for some use cases. Anyway you could open a feature request at https://bugs.ruby-lang.org/issues/ https://bugs.ruby-lang.org/issues/ and see what happens. See the two issues at https://bugs.ruby-lang.org/search?utf8=%E2%9C%93&issues=1&q=List+comprehension+ https://bugs.ruby-lang.org/search?utf8=%E2%9C%93&issues=1&q=... first