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)
Run the above code and {"grade" : 1, "number" : 60171234, 'name' : 'Gildong Hong'}
I want to make sure that these results are printed as strings, but how do I fix them? Also, we need to create a scoreSort
function and use sorted to sort the value value of the dictionary, which method should we use?
I'd appreciate it if you could answer!
python dictionary
Is there a need to make a class??
a = {}
a['grade'] = 1
a['number'] = 60171234
a['name'] = 'Gildong Hong'
print(a)
>> {'grade': 1, 'number': 60171234, 'name': 'Gildong Hong'}
574 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
925 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
626 Uncaught (inpromise) Error on Electron: An object could not be cloned
577 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.