read the file and prduce sorted dictionary
<p>Create a file with contents:  </p>

<pre><code>Mary,Jane : 5.8 Mary,Doe : 6.0 John,Doe : 6.3 John,Muller : 5.6 Mary,Muller : 6.5
</code></pre>

<p>Read this file and create a dictionary with keys of the type tuple and values of the type float  i.e., an item of the dictionary should look like this: </p>

<pre><code>(âMaryâ,âJaneâ) : 5.8
</code></pre>

<p>Convert this dictionary into a list of tuples. Sort them in decreasing order and print them. </p>

<p>my code is: </p>

<pre><code>f = open('sam.txt', 'r')
answer = {}
tuple(answer.keys())
for i in answer:
    print tuple(answer.keys())  
for line in f:

    k, v = ((line.strip()).split(':'))
    answer[((k.strip()))] = float(v.strip())
print answer    
c = answer.items()
d = sorted(c)
print tuple(reversed(sorted(c)))
f.close()
</code></pre>

<p>Here I am getting keys of dictionary as string not tuple as prescribed please tell me my mistake and please do some fine tunes to my regarding problem.</p>

<p>I did answer like this may i know is there any further upgrade needed to it to make it more efficient</p>

<pre><code>f = open('sam.txt')
answer = {tuple(x.split(':')[0].strip().split(',')): float(x.split('[1].strip()) for x in f}
print "\ndictionary taken from file is:\n"
print answer    
c = answer.items()
d = sorted(c)
print "\nafter sorted and converted into tuples the output is:\n"
print tuple(reversed(sorted(c)))
f.close()
</code></pre>

python dictionary