for key, value in sorted(mydict.iteritems(), key=lambda (k,v): (v,k), reverse=True): ^ SyntaxError: invalid syntax