Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I have the following procedure:

def myProc(invIndex, keyWord): 

D={} 

for i in range(len(keyWord)): 

if keyWord[i] in invIndex.keys(): 

D.update(invIndex[query[i]]) 

return D

But I am getting the following error:

Traceback (most recent call last): 

 File "<stdin>", line 3, in <module> 

TypeError:cannot convert dictionary update sequence element #0 to a sequence

I do not get any error if D contains elements. But I need D to be empty at the beginning.

1 Answer

0 votes
by (106k points)

First of all D = {} is a dictionary not set.

And you can check that by using following ways:-

>>> d = {} 

>>> type(d) 

<type 'dict'>

For set you can use D =  set():-

>>> d = set() 

>>> type(d) 

<type 'set'> 

Below is the code for adding items to a set:-

>>> d.update({1}) 

>>> d.add(2) 

>>> d.update([3,3,3]) 

>>> d set

([1, 2, 3])

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

Browse Categories

...