You are reading a single comment by @Greenbank and its replies. Click here to read the full conversation.
  • 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.

  • Ah ok, I thought a set was just a special case of a dict where there are no values, only keys.

  • 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.

    That's a very crucial difference, thanks!

About

Avatar for Greenbank @Greenbank started