Multiple distinct objects: Difference between revisions

added python
m (Formatting fix, added headers)
(added python)
Line 30:
in an appropriate do block. If it is distinguished by, say, a numeric label, one could write
<code haskell>map makeTheDistinctThing [1..n]</code>
 
=={{header|Python}}==
The mistake is often written as:
<code python>[Foo()] * n # here Foo() can be any expression that returns an object</code>
which is incorrect since <code>Foo()</code> is only evaluated once. A common correct version is:
<code python>[Foo() for i in xrange(n)]</code>
which evaluates <tt>Foo()</tt> <var>n</var> times and collects each result in a list.
Anonymous user