(self, val)
| 15 | return True |
| 16 | |
| 17 | def remove(self, val): |
| 18 | if val not in self.num_to_idx: |
| 19 | return False |
| 20 | |
| 21 | idx = self.num_to_idx[val] |
| 22 | last = self.num_list[-1] |
| 23 | |
| 24 | # swap last elem to current spot so you can pop the end |
| 25 | self.num_list[idx] = last |
| 26 | self.num_list.pop() |
| 27 | self.num_to_idx[last] = idx |
| 28 | del self.num_to_idx[val] |
| 29 | |
| 30 | return True |
| 31 | |
| 32 | def getRandom(self): |
| 33 | return random.choice(self.num_list) |