class Queue: def __init__(self, events=None): self.events = [] if events is None else events self.records = [] def enqueue(self, key, cents): if isinstance(cents, bool) or not isinstance(cents, int) or cents <= 0: raise TypeError('positive integer cents required') for previous_id, amount in self.records: if previous_id == key: if amount != cents: raise ValueError('conflicting amount') return 'duplicate' self.events.append({'id': key, 'cents': cents}) self.records.append((key, cents)) return 'queued'