Remove Quotation marks from a dictionary
<p>I have a dictionary of bigrams, obtained by importing a csv and transforming it to a dictionary:</p>

<pre><code>bigram_dict = {"('key1', 'key2')": 'meaning', "('key22', 'key13')": 'mean2'}
</code></pre>

<p>I want keys' dictionary to be without quotation marks, i.e.:</p>

<pre><code>desired_bigram_dict={('key1', 'key2'): 'meaning', ('key22', 'key13'): 'mean2'}
</code></pre>

<p>Would you please suggest me how to do this?</p>

<p>This can be done using a dictionary comprehension, where you call <a href="https://docs.python.org/3/library/ast.html#ast.literal_eval">literal_eval</a> on the key:</p>

<pre><code>from ast import literal_eval
bigram_dict = {"('key1', 'key2')": 'meaning', "('key22', 'key13')": 'mean2'}

res = {literal_eval(k): v for k,v in bigram_dict.items()}
</code></pre>

<p>Result:</p>

<pre><code>{('key22', 'key13'): 'mean2', ('key1', 'key2'): 'meaning'}
</code></pre>

python nltk