---
# System prepended metadata

title: CSPT23 Lecture 6

---

# CSPT23 Lecture 6
## [Design a HashSet]()
```
from collections import deque

class MyHashSet:

    def __init__(self):
        self.list = [None] * 10000
    
    def hashIndex(self, key):
        return hash(key) % len(self.list)

    def add(self, key: int) -> None:
        hashIndex = self.hashIndex(key)
        if self.list[hashIndex] is None:
            newDeque = deque()
            newDeque.append(key)
            self.list[hashIndex] = newDeque
        elif key not in self.list[hashIndex]:
            self.list[hashIndex].append(key)

    def remove(self, key: int) -> None:
        hashIndex = self.hashIndex(key)
        if self.list[hashIndex] is None:
            return
        try:
            self.list[hashIndex].remove(key)
        except:
            pass

    def contains(self, key: int) -> bool:
        hashIndex = self.hashIndex(key)
        if self.list[hashIndex] is None:
            return False
        return key in self.list[hashIndex]
        


# Your MyHashSet object will be instantiated and called as such:
# obj = MyHashSet()
# obj.add(key)
# obj.remove(key)
# param_3 = obj.contains(key)
```