What does the “map” method do in Ruby?

The map method takes an enumerable object and a block, and runs the block for each element, outputting each returned value from the block (the original object is unchanged unless you use map!): Array and Range are enumerable types. map with a block returns an Array. map! mutates the original array. Where is this helpful, and what is the difference between map! and each? Here is an example: … Read more

What is the difference between range and xrange functions in Python 2.X?

In Python 2.x: range creates a list, so if you do range(1, 10000000) it creates a list in memory with 9999999 elements. xrange is a sequence object that evaluates lazily. In Python 3: range does the equivalent of Python 2’s xrange. To get the list, you have to explicitly use list(range(…)). xrange no longer exists.