Creating an empty set

后端 未结 4 2095
刺人心
刺人心 2021-01-03 23:15

I have some code which tots up a set of selected values. I would like to define an empty set and add to it, but {} keeps turning into a dictionary. I have foun

4条回答
  •  旧巷少年郎
    2021-01-03 23:41

    As has been pointed out - the way to get an empy set literal is via set(), however, if you re-wrote your code, you don't need to worry about this, eg (and using set()):

    from operator import itemgetter
    query = ['four', 'two', 'three']
    result = set().union(*itemgetter(*query)(inversIndex))
    # set([0, 1, 2])
    

提交回复
热议问题