using map function to square a list
<p>I have a list which I want to square each of them.</p>

<p>this is what I have done</p>

<pre><code>def square(x):
    return x*x

numbers = [1,2,3,4,5,6]
squares = map(square, numbers)


squares_as_strings = str(squares)


print(','.join(squares_as_strings))
</code></pre>

<p>but the answer is this</p>

<pre><code>[,1,,, ,4,,, ,9,,, ,1,6,,, ,2,5,,, ,3,6,]
</code></pre>

<p>instead of </p>

<pre><code>[1,4,9,16,25,36]
</code></pre>

<p>This is happening because you are calling a <code>join</code> on a string and not on a <code>list</code>. Ultimately, you are not handling the result of your <code>map</code> properly.</p>

<p>If you are using Python 2, your map will give you a list, so simply print out <code>squares</code> and you will have your expected result.</p>

<p>If you are using Python 3, you will actually have a map object, so you will need to call <code>list</code> on it, to obtain a list of your map result: </p>

<pre><code>list(squares)
</code></pre>

python string list