I have a list of objects which I need to store in a dictionary. A property of these objects is title, and this is what I am using as the key when I store the object in the dictionary. I process the title first so that I can use it as the key by removing spaces and truncating it to 50 characters.
However some of the titles are quite long, and the first 50 characters are exactly the same as another title. Because of this the keys are being screwed up. Can anyone advise a better method for doing this. I was thinking about encoding the title in some way and then using that?
You don’t need to remove spaces or truncate the title to use it as a dictionary key. Python dictionary keys can be any immutable Python type,
stramong them (even long ones with spaces and special characters).Just use the entire title, or encode the title using a hash: