Is there a way to return a dictionary value without quotations?
<p>Sorry if this is somewhere out there but I just couldn't find a solution to what I was looking for. I want to return the value of my dictionary without the quotations and can't figure out what I'm doing wrong.</p>

<pre><code>def read_wiktionary():
 answer = dict()
 f = open('wiktionary.txt', 'r')
 for line in f:
      word,value = line.rstrip('\n').split(' ')
      answer[word] = (value)
 return answer
</code></pre>

<p>When you read a file, everything is read as a string. To get a float value, you'll need to cast it to a float.</p>

<pre><code>def read_wiktionary():
    answer = dict()
    f = open('wiktionary.txt', 'r')
    for line in f:
        word, value = line.rstrip('\n').split(' ')
        answer[word] = float(value)
    return answer
</code></pre>

<p>As an aside, it's generally good practice to use <code>with</code> to open a file so that it will automatically be closed when it exits the block. From <a href="https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects" rel="nofollow">the docs</a>:</p>

<blockquote>
  <p>It is good practice to use the with keyword when dealing with file
  objects. This has the advantage that the file is properly closed after
  its suite finishes, even if an exception is raised on the way.</p>
</blockquote>

<p>So, I would suggest:</p>

<pre><code>def read_wiktionary():
    answer = {}
    with open('wiktionary.txt', 'r') as f:
        for line in f:
            word, value = line.rstrip('\n').split(' ')
            answer[word] = float(value)
    return answer
</code></pre>

python dictionary return