Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tal95shah/49365bad8dec35ca27f55fa41c3882d3 to your computer and use it in GitHub Desktop.

Select an option

Save tal95shah/49365bad8dec35ca27f55fa41c3882d3 to your computer and use it in GitHub Desktop.
Sortable Dataclasses without field objects
from dataclasses import dataclass
@dataclass(frozen=True,order=True)
class Employee(object):
id: int
name: str
salary: int
if __name__ == '__main__':
emp = Employee(1,"Talha Gillani",5000)
emp2= Employee(100,"Syed Talha Gillani",10000)
employeeList=[emp2,emp]
print("EmployeeList:{}".format(employeeList))
employeeList.sort()
print("EmployeeList:{}".format(employeeList))
print("emp:{}".format(emp))
print("emp2:{}".format(emp2))
print("emp == emp2:{}".format(emp == emp2))
print("emp != emp2:{}".format(emp != emp2))
print("emp >= emp2:{}".format(emp >= emp2))
print("emp <= emp2:{}".format(emp <= emp2))
print("emp > emp2:{}".format(emp > emp2))
print("emp < emp2:{}".format(emp < emp2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment