CSV Example 4(find the sorted by salaries)


salaries.csv
===========

['deepak', 'hyderabad', '2000']
['santosh', 'guntur', '3000']
['sachin', 'hyderabad', '2000']


csvtest.py
========
import csv

with open('salaries.csv','rb') as f:
    reader=csv.reader(f)
   
    sorted_salary=sorted(reader, key=lambda t: int( t[2] ), reverse=True)
  
    for row in sorted_salary:
        #print row[0]
        #if row[0]=='deepak':
        print row



o/p
===

>>> import csvtest
['santosh', 'guntur', '3000']
['deepak', 'hyderabad', '2000']
['sachin', 'hyderabad', '2000']
>>>

No comments:

Post a Comment