Help me to solve assignment 2
You need to specify what’s the problem you’ve experienced.
when I solve question-1 ,How to insert data in form of ‘key’ and ‘value’
I’m not sure what you mean because of scarce information, but I guess you could use tuple.
class HashTable: def insert(self, key, value): """Insert a new key-value pair""" pass def find(self, key): """Find the value associated with a key""" pass def update(self, key, value): """Change the value associated with a key""" pass def list_all(self): """List all the keys""" pass
talking about this how to insert data
As I said, use tuple.
but how to store multiple value please give me full code if you solve this …
A tuple is a special kind of variable which can be used to store multiple values at once. In this case you want to store 2 values: the key and it’s associated value →
Since you want to have your hashtable be able to store more than one such pair, you need to add it to a list (
That’s for the
find() → iterate over the list and find if the key matches any of the keys in a list of key-value pairs.
update() → find the index where the pair is stored, then replace it with a new pair
list_all() → just iterate over the list and return a list of keys (you might need to create a “return list” - variable with a list of keys, which you then return)
why is not working
append() doesn’t return any value (or more technically: it returns
What is proper solution of this Question pleas help
I’ve already gave you hints how to solve this problem.
You need to learn following things:
- unpacking tuples
- immutability of tuples
- iterating over lists
- adding values to a list
- classes in python
- meaning of
- usage of
- meaning of
Using this knowledge and my hints from one of the previous posts you should be able to code this up.
thank you for giving me your valuable advice. it is very help full for me and help me further.