converting dictionary to string and string to dict
<p>I have the following code:</p>

<pre><code>&gt;&gt;&gt; word_array = defaultdict(list)
&gt;&gt;&gt; word_array['first'].append(1)
&gt;&gt;&gt; word_array['first'].append(2)
&gt;&gt;&gt; word_array
defaultdict(&lt;type 'list'&gt;, {'first': [1, 2]})
</code></pre>

<p>I converted it to string the whole data structure, but when i try to convert it from string i can't, i get the following:</p>

<pre><code>&gt;&gt;&gt; ast.literal_eval(str(word_array))
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/lib/python2.7/ast.py", line 49, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/usr/lib/python2.7/ast.py", line 37, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "&lt;unknown&gt;", line 1
    defaultdict(&lt;type 'list'&gt;, {'first': [1, 2]})
                ^
SyntaxError: invalid syntax
</code></pre>

<p>Is there any better solution to this.</p>
