Skip to content

Commit

Permalink
Merge pull request srehwald#1 from jpbernius/sort-ingredients-json
Browse files Browse the repository at this point in the history
Sort ingredients in JSON Output
  • Loading branch information
COM8 authored Sep 4, 2019
2 parents 8bfee18 + 1f91975 commit 13207ea
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def __init__(self, name, price, ingredients):

def __repr__(self):
if type(self.price) is not str:
return "%s %s: %.2f€" % (self.name, str(list(self.ingredients)), self.price)
return "%s %s: %.2f€" % (self.name, str(sorted(self.ingredients)), self.price)
else:
return "%s %s: %s" % (self.name, str(list(self.ingredients)), self.price)
return "%s %s: %s" % (self.name, str(sorted(self.ingredients)), self.price)

def __eq__(self, other):
if isinstance(other, self.__class__):
Expand All @@ -29,7 +29,7 @@ def __eq__(self, other):

def to_json_obj(self):
return {"name": self.name, "price": self.price,
"ingredients": list(self.ingredients)}
"ingredients": sorted(self.ingredients)}

def __hash__(self):
# http://stackoverflow.com/questions/4005318/how-to-implement-a-good-hash-function-in-python
Expand Down

0 comments on commit 13207ea

Please sign in to comment.