Apply a callback to an array: Difference between revisions

(→‎{{header|Perl}}: Added spaces to blank lines to make code sample a contiguous block)
Line 652:
 
=={{header|Python}}==
<prepython>
def square(n):
return n * n
Line 671:
import itertools
isquares2 = itertools.imap(square, numbers) # iterator, lazy
</prepython>
To print squares of integers in the range from 0 to 9, type:
<python>print " ".join(str(n * n) for n in range(10))</python>
Or:
<python>print " ".join(map(str, map(square, range(10))))</python>
Result:
<python>0 1 4 9 16 25 36 49 64 81</python>
 
=={{header|Raven}}==
Anonymous user