class Kamus:
def __init__(self):
self.data = {}
def tambah(self, kata, sinonim):
if kata not in self.data:
self.data[kata] = []
self.data[kata] = list(set(self.data[kata] + sinonim))
for kata_sinonim in sinonim:
if kata_sinonim not in self.data:
self.data[kata_sinonim] = []
if kata not in self.data[kata_sinonim]:
self.data[kata_sinonim].append(kata)
def ambilSinonim(self, kata):
return self.data.get(kata, None)
kamus = Kamus()
kamus.tambah("big", ["large", "great"])
kamus.tambah("big", ["huge", "fat"])
kamus.tambah("huge", ["enormous", "gigantic"])
print(kamus.ambilSinonim("big"))
print(kamus.ambilSinonim("huge"))
print(kamus.ambilSinonim("gigantic"))
print(kamus.ambilSinonim("colossal"))
Y2xhc3MgS2FtdXM6CiAgICBkZWYgX19pbml0X18oc2VsZik6CiAgICAgICAgc2VsZi5kYXRhID0ge30KICAgICAgICAKICAgIGRlZiB0YW1iYWgoc2VsZiwga2F0YSwgc2lub25pbSk6CiAgICAgICAgaWYga2F0YSBub3QgaW4gc2VsZi5kYXRhOgogICAgICAgICAgICBzZWxmLmRhdGFba2F0YV0gPSBbXQogICAgICAgICAgICAKICAgICAgICBzZWxmLmRhdGFba2F0YV0gPSBsaXN0KHNldChzZWxmLmRhdGFba2F0YV0gKyBzaW5vbmltKSkKICAgICAgICAKICAgICAgICBmb3Iga2F0YV9zaW5vbmltIGluIHNpbm9uaW06CiAgICAgICAgICAgIGlmIGthdGFfc2lub25pbSBub3QgaW4gc2VsZi5kYXRhOgogICAgICAgICAgICAgICAgc2VsZi5kYXRhW2thdGFfc2lub25pbV0gPSBbXQogICAgICAgICAgICBpZiBrYXRhIG5vdCBpbiBzZWxmLmRhdGFba2F0YV9zaW5vbmltXToKICAgICAgICAgICAgICAgIHNlbGYuZGF0YVtrYXRhX3Npbm9uaW1dLmFwcGVuZChrYXRhKQogICAgICAgICAgICAgICAgCiAgICBkZWYgYW1iaWxTaW5vbmltKHNlbGYsIGthdGEpOgogICAgICAgIHJldHVybiBzZWxmLmRhdGEuZ2V0KGthdGEsIE5vbmUpCgprYW11cyA9IEthbXVzKCkKa2FtdXMudGFtYmFoKCJiaWciLCBbImxhcmdlIiwgImdyZWF0Il0pCmthbXVzLnRhbWJhaCgiYmlnIiwgWyJodWdlIiwgImZhdCJdKQprYW11cy50YW1iYWgoImh1Z2UiLCBbImVub3Jtb3VzIiwgImdpZ2FudGljIl0pCgpwcmludChrYW11cy5hbWJpbFNpbm9uaW0oImJpZyIpKSAgICAgIApwcmludChrYW11cy5hbWJpbFNpbm9uaW0oImh1Z2UiKSkgICAgIApwcmludChrYW11cy5hbWJpbFNpbm9uaW0oImdpZ2FudGljIikpCnByaW50KGthbXVzLmFtYmlsU2lub25pbSgiY29sb3NzYWwiKSkg