When accessing dictionary values, how to impute 'NaN' if no value exists for a certain key?
<p>I am looping through dictionaries and accessing the dictionary values to append to a list. </p>

<p>Consider one dictionary as an example, <code>example_dict</code>:</p>

<pre><code>example_dict = {"first":241, "second": 5234, "third": "Stevenson", "fourth":3.141592...}
first_list = []
second_list = []
third_list = []
fourth_list = []
...
first_list.append(example_dict["first"])  # append the value for key "first"
second_list.append(example_dict["second"])  # append the value for key "second"
third_list.append(example_dict["third"])     # append the value for key "third"
fourth_list.append(example_dict["fourth"])   # append the value for key "fourth"
</code></pre>

<p>I am looping through hundreds of dictionaries. It is possible that some keys do not have values. In this case, I would like an <code>NaN</code> appended to the lists---after running the script, each list should have the same number of elements. </p>

<p>If <code>new_dict = {"first":897, "second": '', "third": "Duchamps", ...}</code>, then <code>second_list.append(new_dict["second"])</code> would append <code>NaN</code>. </p>

<p>How does one write in a check for this to occur? An if statement?</p>