I am new to Python and am curious if I am doing this correctly. I have a tuple of dicts (from a database call):
companies = ( { 'companyid': 1, 'companyname': 'Company C' },
{ 'companyid': 2, 'companyname': 'Company A' },
{ 'companyid': 3, 'companyname': 'Company B' } )
I want to sort this on companyname. Is there a more correct way than this to do it?
sortcompanies = list(companies)
sortcompanies.sort(lambda x,y: cmp(x['companyname'],y['companyname']))
Thanks for your criticism!