Using `map` to write lines to files
<p>I have a list of lines:</p>

<pre><code>lines = [a,b,c,d]
</code></pre>

<p>And a list of files (created via <code>open(path string,'w')</code>:</p>

<pre><code>files = [e,f,g,h]
</code></pre>

<p>What I am trying to do is write each line to its respective file (line <code>a</code> should go with file <code>e</code> and a new line). Note, this is all part of a much larger loop to generate the lines and put them in this list of lines you see:</p>

<p>This is my current method:</p>

<pre><code>map(lambda (x,y): y.write(x) + "\n",zip(lines,files))
</code></pre>

<p>But this is what I am getting:</p>

<pre><code>TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
</code></pre>

<p>What is a way of achieving what I need? Writing each line to each file separately is very cumbersome.</p>

<p>Did you mean to do:</p>

<pre><code>map(lambda (x,y): y.write(x + "\n"), zip(lines,files))
</code></pre>

<p>But I'd rather do it as:</p>

<pre><code>for l, f in zip(lines,files):
    f.write(l + "\n")
</code></pre>

python python-2.7 function dictionary lambda