BdW44222

03. Catalogue

Jun 25th, 2021
1,162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Catalogue:
  2.     def __init__(self, name):
  3.         self.name = name
  4.         self.products = []
  5.  
  6.     def add_product(self, product):
  7.         self.products.append(product)
  8.  
  9.     def get_by_letter(self, first_letter):
  10.         return [el for el in self.products if el.startswith(first_letter)]
  11.  
  12.     def __repr__(self):
  13.         result = f" Items in the {self.name} catalogue:\n"
  14.         result += '\n'.join(sorted(self.products))
  15.         return result
RAW Paste Data