How to write a dictionary of lists to a csv file?
<p>I have this dictionary of lists that I want to write it in a CSV file:</p>

<pre><code>file2_Dict =  {'id': ' ', 'gender': ['M', 'M'], 'name': ['Smith', 'John'], 'city': ['Omaha','Lincoln']}
</code></pre>

<p>The problem is that not all the keys of the dictionary have a list of items as a value.  In this case the key (i.e.<code>'id'</code>) has a string as value (i.e. <code>" "</code>).  I tried to use the solution provided by <a href="https://stackoverflow.com/questions/23613426/write-dictionary-of-lists-to-a-csv-file">Tim Pietzcker</a>, but this only outputs the header of the csv file (keys of the dictionary), like this:</p>

<pre><code>id, gender, name, city
</code></pre>

<p>The expected output should be, like this:</p>

<pre><code> id, gender, name, city
  ,M,Smith,Omaha
  ,M,John,Lincoln
</code></pre>

<p>Any idea how to solve this problem?   </p>