Home > front end >  Cannot unpack non-iterable object
Cannot unpack non-iterable object

Time:12-20

I have a basic doubt about the following;

D = [{'one':1,'two':'Hello','three':3},{'four':4,'five':'World!','six':6}]
for a,b,c in list(D[0].values()):
    print(a,b,c)

It gives the following error;

TypeError: cannot unpack non-iterable int object

I know there are certain solutions related to the similar problem but I am still not able to resolve the problem. Please help me resolve this problem. Thank You.

CodePudding user response:

Keep in mind that list(D[0].values()) is already a list, so you want either a for loop or an expansion assignment, not both together:

a, b, c = list(D[0].values())
print(a, b, c)
  • Related