Reputation: 1855
I have a dictionary name typecontext and I have a list named types. I want to take five elements of types and add it to the dict typecontext. I am getting a error that set attribute has no object getitem.
try:
k=0
typecontext = dict()
for i in range(0, len(types), 5):
print(i)
if i + 5 < len(types):
typecontext.update({'item_'+str(k) :types[i:i + 5]})
else:
typecontext.update({'item_' + str(k): types[i:len(types)]})
k=k+1
except Exception as e:
print(e)
Upvotes: 1
Views: 673
Reputation: 487
It looks like your variable types
is a set
object. So when you try to slice it you get your error.
Upvotes: 3