# Python(Map data structure)Review or feedback

**URL:** <https://forum.freecodecamp.org/t/python-map-data-structure-review-or-feedback/408927>\
**Category:** I Built This\
**Created:** [July 10, 2020, 4:24pm UTC](https://forum.freecodecamp.org/t/python-map-data-structure-review-or-feedback/408927 "2020-07-10T16:24:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![topcoder](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/topcoder/32/145507_2.png) [@topcoder](https://forum.freecodecamp.org/u/topcoder)\
**Post date:** [July 10, 2020, 4:24pm UTC](https://forum.freecodecamp.org/t/python-map-data-structure-review-or-feedback/408927/1 "2020-07-10T16:24:08Z")

</div>

```auto
#Map abstract data structure experiment

#hash_ object which has keys list and values list
class hash_:
    def __init__ (self):
        self.slots = [None] * 11
        self.data = [None] * 11

hash_obj = hash_()
hash_obj.slots[3] = 12
print(hash_obj.slots,hash_obj.data)

#this function is to get the hashvalue or generate a position based on the key value [0,10] we pass as an argument
def hash_val(key,size):
    return key%size

#this function is to generate a (position + 1),an extened position value to check or iterate if possible
def rehash_val(key,size):
    return (((hash_val(2,len(key)))%size)+1)% size

def Hash_function(key,data):
    hash_value = hash_val(key,len(hash_obj.slots))

    if hash_obj.slots[hash_value] == None:
        hash_obj.slots[hash_value] = key
        hash_obj.data[hash_value] = data

    else:
        if hash_obj.slots[hash_value] == key:
            hash_obj.slots[hash_value] = key
        
        else:
            next_val = rehash_val(key,len(hash_obj.slots))
            while hash_obj.slots[hash_value] != None and hash_obj.slots[hash_value] != key:
                #repeat the if and else conditions again and apply the rehash function to moves forward
                if hash_obj.slots[hash_value] == None:
                    hash_obj.slots[hash_value] = key
                    hash_obj.data[hash_value] = data

                else:
                    if hash_obj.slots[hash_value] == key:
                        hash_obj.slots[hash_value] = key

Hash_function(3,hash_val(3,len(hash_obj.slots)))

print(hash_obj.slots,hash_obj.data)

```

I wrote a function that loops through a list of length 11 with only None values.As it is based on Hashing .Can someone review the whole algorithm.But the problem of collision is still not solved.Correct this if possible

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 1:15pm UTC](https://forum.freecodecamp.org/t/python-map-data-structure-review-or-feedback/408927/2 "2021-06-01T13:15:24Z")

</div>


