Advertisement
BdW44222

03. Catalogue

Jun 25th, 2021
1,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement