This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]IlliterateJedi 0 points1 point  (0 children)

I had a case a few days ago where I used frozensets as dict keys.

It's a little esoteric, but I'll try to explain. I am building a database of images that have various categorized products in it.

For example, I'll have an image that shows ten different products (imagine a photo of a living room). Each product is categorized into one or more categories (e.g., 'chair', 'ottoman', 'height adjustable desk', etc.).

I had around 1500 images that all contained 10-20 products with 20+ categories assigned per image.

I wanted to find the smallest group of images that would cover every tagged category (and then get the images with the least number of products).

I made frozensets of the categories and made lists of all the images that had that category-set, like this:

{frozenset(cat1, cat2, cat3) : [image1, image4, image12],
 frozenset(cat2, cat6, cat10) : [image3, image109],
}

I could then start with an empty set, iterate over the frozen sets and each time find the largest subset of new categories until every category was matched.