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"""

def find(self, key):
    """Find the value associated with a key"""

def update(self, key, value):
    """Change the value associated with a key"""

def list_all(self):
    """List all the keys"""

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 → (key, 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 ([] and append() method).
That’s for the insert().

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

Because append() doesn’t return any value (or more technically: it returns None).

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:

  • tuples
    • unpacking tuples
    • immutability of tuples
  • lists
    • iterating over lists
    • adding values to a list
  • classes in python
    • meaning of self in classes
    • usage of __init__ (class constructor)

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.