-
How come you used a dictionary with all values of 1, rather than a list or a set?
Because searching through a list is just like a for loop, it needs to check each item in turn until it finds the item or runs out of items to check.
A python dict is based on a hash table, lookups are almost immediate and lookup performance is consistent regardless of the number of items stored in the dict (assuming you've got a sensible dict implementation). A dict takes a little longer to setup and insert values (and consumes a bit more memory) but that's a small price to pay for the massively faster lookup performance.
How come you used a dictionary with all values of 1, rather than a list or a set?