I have a code that picks up a set of selected values. I would like to define an empty set and add to it, but {} continues to turn into a dictionary. I found that if I populate a set with a dummy value, I can use it, but it's not very elegant. Can someone tell me the correct way to do this? Thank you
inversIndex = {'five': {1}, 'ten': {2}, 'twenty': {3}, 'two': {0, 1, 2}, 'eight': {2}, 'four': {1}, 'six': {1}, 'seven': {1}, 'three': {0, 2}, 'nine': {2}, 'twelve': {2}, 'zero': {0, 1, 3}, 'eleven': {2}, 'one': {0}} query = ['four', 'two', 'three'] def orSearch(inverseIndex, query): b = [ inverseIndex[c] for c in query ] x = {'dummy'} for y in b: { x.add(z) for z in y } x.remove('dummy') return x orSearch(inverseIndex, query)
{0, 1, 2}
source share