How can I add items to an empty set in python

前端 未结 3 1057
猫巷女王i
猫巷女王i 2021-01-30 04:55

I have the following procedure:

def myProc(invIndex, keyWord):
    D={}
    for i in range(len(keyWord)):
        if keyWord[i] in invIndex.keys():
                      


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 05:20

    D = {} is a dictionary not set.

    >>> d = {}
    >>> type(d)
    
    

    Use D = set():

    >>> d = set()
    >>> type(d)
    
    >>> d.update({1})
    >>> d.add(2)
    >>> d.update([3,3,3])
    >>> d
    set([1, 2, 3])
    

提交回复
热议问题