I have this dataset. I want to update the MySQL table. I can do it in the current form but I thought a conversion to dictionary will shrink the list to be updated.
My dataset :
dataset = [('121', set(['NY'])), ('132', set(['CA', 'NY'])), ('198', set(['NY'])), ('676', set(['NY'])), ('89', set(['NY', 'CA']))]
Desired output :
A dictionary :
output = {'set(['NY'])':121,198,676, 'set(['CA', 'NY'])':132,89}
You must use a frozenset for the key. There is no guarantee that a set with the same elements will always be turned into the same
reprortupleas sets are unordered. Unless you sort the set elements first of course, but that seems wastefulor using a sorted tuple
Random example to illustrate this