Suppose I have quantities of fruits of different colors, e.g., 24 blue bananas, 12 green apples, 0 blue strawberries and so on. I\'d like to organize them in a data structur
This type of data is efficiently pulled from a Trie-like data structure. It also allows for fast sorting. The memory efficiency might not be that great though.
A traditional trie stores each letter of a word as a node in the tree. But in your case your "alphabet" is different. You are storing strings instead of characters.
it might look something like this:
root: Root
/|\
/ | \
/ | \
fruit: Banana Apple Strawberry
/ | | \
/ | | \
color: Blue Yellow Green Blue
/ | | \
/ | | \
end: 24 100 12 0
see this link: trie in python