I built a dictionary list like this
lst = [{'name': nameobj, Classobj1: "string", Classobj2: "string"}, \
{'name': nameobj, Classobj1: "string", Classobj2: "string"}]
and I’m using
for dic in lst:
for k,v in dic: # here is the line has probloem! What it happens?
#process
The error message is like “Classname” object is not iterable.
Iterating over a dictionary just iterates over the keys, not key-value pairs. So on the line
Python is taking just a key, such as Classobj1, and trying to unpack it to match it to the tuple k,v. Since Classobj1 can’t be iterated over, it can’t be unpacked to match two items, which is why you get this error.
To iterate over key-value pairs, use items() or iteritems():