Advertisement
simeonshopov

Catalogue

Jan 20th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. class Catalogue:
  2.     def __init__(self, name: str):
  3.         self.name = name
  4.         self.products = []
  5.  
  6.     def add_product(self, product: str):
  7.         self.products.append(product)
  8.  
  9.     def get_by_letter(self, letter: str):
  10.         stuff = [x for x in self.products if x.startswith(letter)]
  11.         return stuff
  12.  
  13.     def __repr__(self):
  14.         result = ''
  15.         result += f"Items in the {self.name} catalogue:\n"
  16.         result += '\n'.join(sorted(self.products))
  17.         return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement