I have a Job class. Here’s a simplified version with some sample jobs:
class Job:
def __init__(self, type):
self.type = type
def __repr__(self):
return '< %s >' % self.type
job1 = Job('Copy')
job2 = Job('Delete')
job3 = Job('Scan')
jobs = [job1,job2,job3]
In my application, the jobs are added to the jobs list (from a db) somewhat randomly, but I need to ensure that any Delete jobs take place last. The simplest way I can think of is to ensure the Delete jobs are moved to the end of the list, then the list is processed in order. However, I’m not sure how to do that when the sort criteria is an attribute of a Class, and is there any guaranty that the list will be iterated in order when the jobs are processed? Any advice would be great.
The key will be
Falsefor “Copy” or “Scan” jobs andTruefor “Delete” jobs. SinceTrue>Falsethe “Delete” jobs will be sorted to the end