Python map function, passing by reference/value?
<p>I have a question about the <code>map</code> function in Python.</p>

<p>From what I understand, the function does not mutate the list it's operating on, but rather create a new one and return it. Is this correct ?</p>

<p>Additionally, I have the following piece of code</p>

<pre><code>def reflect(p,dir):
  if(dir == 'X'):
    func = lambda (a,b) : (a * -1, b)
   else:
    func = lambda (a,b) : (a, b * -1)
  p = map(func,p)
  print 'got', p
</code></pre>

<p><code>points</code> is an array of tuples such as: <code>[(1, 1), (-1, 1), (-1, -1), (1, -1)]</code></p>

<p>If I call the above function in such a manner:</p>

<pre><code>print points
reflect(points,'X')
print points
</code></pre>

<p>the list <code>points</code> does not change. Inside the function though, the print function properly prints what I want.</p>

<p>Could someone maybe point me in some direction where I could learn how all this passing by value / reference etc works in python, and how I could fix the above ? Or maybe I'm trying too hard to emulate Haskell in python...</p>

<p>Thanks</p>

<p>edit:</p>

<p>Say instead of <code>p = map(func,p)</code> I do </p>

<pre><code>for i in range(len(p)):
  p[i] = func(p[i])
</code></pre>

<p>The value of the list is updated outside of the function, as if working by reference. Ugh, hope this is clear :S</p>
