fork download
  1. class Kamus:
  2. def __init__(self):
  3. self.data = {}
  4.  
  5. def tambah(self, kata, sinonim):
  6. if kata not in self.data:
  7. self.data[kata] = []
  8.  
  9. self.data[kata].extend(sinonim)
  10.  
  11. def ambilSinonim(self, kata):
  12. if kata not in self.data:
  13. return None
  14.  
  15. return [kata] + self.data[kata]
  16.  
  17.  
  18. kamus = Kamus()
  19.  
  20. kamus.tambah('big', ['large', 'great'])
  21. kamus.tambah('big', ['huge', 'fat'])
  22. kamus.tambah('huge', ['enormous', 'gigantic'])
  23.  
  24. print(kamus.ambilSinonim('big'))
  25. print(kamus.ambilSinonim('huge'))
  26. print(kamus.ambilSinonim('gigantic'))
  27. print(kamus.ambilSinonim('colossal'))
  28.  
Success #stdin #stdout 0.07s 14188KB
stdin
Standard input is empty
stdout
['big', 'large', 'great', 'huge', 'fat']
['huge', 'enormous', 'gigantic']
None
None