Parsing dict keys and values and writing/appending data to a file
<p>I have the following and need some guidance on python implementation..I clearly documented the algorithm and the expected output..any inputs are truly appreciated..</p>

<pre><code>data_changes ={'305403': ['302180'], '312994': ['311957'], '311957': ['312621'] }
modem_changes = {'305403': [], '313113': [], '312994': ['253036', '312591'], '311957': []}

for keys that are present in both data_changes and modem_changes:
        write data to a file "file.txt" in the order key--&gt;data_changes_values--&gt;modem_changes_values

for keys that exist in only one of data_changes and modem_changes :
        append data to the same file "file.txt" key--&gt; data_changes_values or key--&gt;modem_changes values

EXPECTED OUTPUT:-

Create a text file with the following data

305403 302180
312994 311957 253036 312591
311957 312621
313113
</code></pre>

<p>Following is what I tried but not serving my purpose...</p>

<pre><code>build_dep_list= [i
for k, v in itertools.chain.from_iterable(d.iteritems() for d in (data_changes, modem_changes))
for i in [k] + (v or [])
if i]
print "BUILD LIST"
print list(set(build_dep_list))

CURRENT OUTPUT:-
['305403', '302180', '313113', '311957', '312621', '253036', '312994', '312591']
</code></pre>
