Skip to content

Commit

Permalink
Show how to sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammar64 committed Nov 7, 2024
1 parent 2dccd0e commit db4def5
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions ensure_sorted.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
BLUE = '\033[94m'
CYAN = '\033[96m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
Expand All @@ -30,6 +30,15 @@ def is_sorted(self):
# I know not effiencent
return sorted(self.apps) == self.apps

# Tell exactly where it's unsorted
def where_unsorted(self):
for i in range(1, len(self.apps)):
if self.apps[i] < self.apps[i-1]:
return f'App {bcolors.RED}{self.apps[i-1]}{bcolors.ENDC} is not in the correct order'

def get_sorted_list(self):
return sorted(self.apps)

def __str__(self):
return str(self.apps)

Expand Down Expand Up @@ -64,7 +73,11 @@ def main():
all_sorted = True
for i in categories:
if not i.is_sorted():
print(f'Category {bcolors.OKBLUE}{i.name}{bcolors.ENDC} is not sorted')
print(f'Category {bcolors.BLUE}{i.name}{bcolors.ENDC} is not sorted')
print(' ' + i.where_unsorted())
print(' Should be sorted as follows:')
for j in i.get_sorted_list():
print(f' {j}')
all_sorted = False

if not all_sorted:
Expand Down

0 comments on commit db4def5

Please sign in to comment.