title: Sorting the CSV file based on by descending order of lawyer salary
body: <p>I must use Python to solve this. Given a file <code>salaries.csv</code> with this structure:</p>
  
  <pre><code>City,Job,Salary
  
  Delhi,Doctors,500
  
  Delhi,Lawyers,400
  
  Delhi,Plumbers,100
  London,Doctors,800
  London,Lawyers,700
  London,Plumbers,300
  Tokyo,Doctors,900
  Tokyo,Lawyers,800
  Tokyo,Plumbers,400
  Lawyers,Doctors,300
  Lawyers,Lawyers,400
  Lawyers,Plumbers,500
  Hong Kong,Doctors,1800
  Hong Kong,Lawyers,1100
  Hong Kong,Plumbers,1000
  Moscow,Doctors,300
  Moscow,Lawyers,200
  Moscow,Plumbers,100
  Berlin,Doctors,800
  Berlin,Plumbers,900
  Paris,Doctors,900
  Paris,Lawyers,800
  Paris,Plumbers,500
  Paris,Dog catchers,400
  </code></pre>
  
  <p>Sorting the CSV file based on by descending order of lawyer salary</p>
  
  <p>The output should the like this: </p>
  
  <pre><code>Tokyo,800
  
  London,700
  
  Delhi,400
  </code></pre>
  
  <p>I am using the following code.,</p>
  
  <pre><code>import csv       
  reader = csv.DictReader(open('salaries.csv','rb'))    
  rows = sorted(reader)    
  a={}    
  for i in xrange(len(rows)):    
      if rows[i].values()[2]=='Lawyers':    
          a[rows[i].values()[1]]=rows[i].values()[0]    
  t = [i for i in sorted(a, key=lambda key:a[key], reverse=True)]    
  p=a.values()    
  p.sort()    
  p.reverse()    
  for i in xrange(len(a)):    
      print t[i]+","+p[i]
  </code></pre>
  
  <p>However, I am getting the following error: </p>
  
  <pre><code>NameError("global name 'a' is not defined",)
  </code></pre>
  
  <p>Can someone help me, please?</p>