I'm having a problem with appending a value list to another list

Viewed 27

I was asked to hash some values to a list and then add this list to another list every time I add an element to it.

The problem I'm facing is that whenever I'm appending the small list to the big one, it appends the list after being fully hashed.

The code I wrote is below. I'm using python 3 on jupyter notebook

def original_hash_value(x, M=13):
    return x % M

def hash_linear_probe(x, i=1, M=13):
    return (original_hash_value(x) + i) % M


def make_answer(keys):
    answer = []
    keylst = ["_"] * M
    
    for value in keys:
        newlst = keylst
       
        condition = True
        ndx = original_hash_value(value)
        i = 1
        while condition:
            if keylst[ndx] == "_":
                keylst[ndx] = value
                answer.append(keylst)
                condition = False 
            else:   
                ndx = hash_linear_probe(value, i)
                i+=1
        
    return answer

keys = [218, 331, 315, 56, 50, 143, 287, 118, 105, 263]
student_answer = make_student_answer(keys)
print(student_answer)
0 Answers
Related