class HashMap:
def __init__(self):
self.vals = {}
def insert(self, key, val):
self.vals = {key:val}
def __str__(self):
result = ''
for i in self.vals.items():
result = result + str(i) + ','
return '{' + result[:-1] + '}'
hashMap = HashMap()
hashMap.insert("grade", 1)
hashMap.insert("number", 60171234)
hashMap.insert("name", "Gildong Hong")
print(hashMap)
I'll run the code {"grade" : 1, "number" : 60171234, 'name' : 'Gildong Hong'} I want these results to be printed as a string, but I can't add dictionary values and the last output result is not as I thought How can I fix it? I'd appreciate your help
python class dictionary
class HashMap:
def __init__(self):
self.vals = {}
def insert(self, key, val):
self.vals[key] = val
The biggest problem was to keep resetting from insert
.
__str___
is a little wrong in the output format, but I'm sure you'll fix it well.
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.