AttributeError: 'list' object has no attribute 'values'

When I run the code, getting the error as:

AttributeError: 'list' object has no attribute 'values'
AttributeError                            Traceback (most recent call last)
<ipython-input-37-66115a52c5d6> in <module>
     23     optimizer.zero_grad()
     24 
---> 25     output = model(X_tr)
     26     optimizer.zero_grad()
     27     loss = loss_func(output)

~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
    887             result = self._slow_forward(*input, **kwargs)
    888         else:
--> 889             result = self.forward(*input, **kwargs)
    890         for hook in itertools.chain(
    891                 _global_forward_hooks.values(),

<ipython-input-34-4a7275625fa6> in forward(self, x)
     13 
     14     def forward(self,x):
---> 15         h = self.f(x)
     16         return self.g(h)
     17 

~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
    887             result = self._slow_forward(*input, **kwargs)
    888         else:
--> 889             result = self.forward(*input, **kwargs)
    890         for hook in itertools.chain(
    891                 _global_forward_hooks.values(),

<ipython-input-32-ae2fe8e8ca2d> in forward(self, x)
     34         x = self.fc(x[:, -1, :])
     35         # out.size() --> 100, 10
---> 36         x = self.hybrid(x)
     37         return T.cat((x, 1 - x), -1)

~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
    887             result = self._slow_forward(*input, **kwargs)
    888         else:
--> 889             result = self.forward(*input, **kwargs)
    890         for hook in itertools.chain(
    891                 _global_forward_hooks.values(),

<ipython-input-6-f66b87fe8d6c> in forward(self, input)
     42 
     43     def forward(self, input):
---> 44         return HybridFunction.apply(input, self.quantum_circuit, self.shift)

<ipython-input-6-f66b87fe8d6c> in forward(ctx, input, quantum_circuit, shift)
      8         ctx.quantum_circuit = quantum_circuit
      9 
---> 10         expectation_z = ctx.quantum_circuit.run(input[0].tolist())
     11         result = torch.tensor([expectation_z])
     12         ctx.save_for_backward(input, result)

<ipython-input-4-34122f68ae18> in run(self, thetas)
     30         result = job.result().get_counts()
     31 
---> 32         counts = np.array(list(result.values()))
     33         states = np.array(list(result.keys())).astype(float)
     34 

AttributeError: 'list' object has no attribute 'values'

The error seems to be raised in ctx.quantum_circuit.run which seems to be another library.
Since result.values() and result.keys() are expected, I would assume this method expects results to be a dict and not a list.

The output of result is below which already has key value pairs.

RESULT [{'1': 49, '0': 51}, {'1': 58, '0': 42}, {'1': 48, '0': 52}, {'0': 53, '1': 47}, {'0': 51, '1': 49}, {'0': 51, '1': 49}, {'1': 58, '0': 42}, {'0': 47, '1': 53}, {'1': 54, '0': 46}, {'0': 47, '1': 53}, {'0': 41, '1': 59}, {'0': 52, '1': 48}, {'1': 47, '0': 53}, {'1': 52, '0': 48}, {'0': 52, '1': 48}, {'1': 50, '0': 50}, {'0': 41, '1': 59}, {'1': 54, '0': 46}, {'1': 55, '0': 45}, {'1': 44, '0': 56}, {'1': 61, '0': 39}, {'1': 53, '0': 47}, {'0': 40, '1': 60}, {'1': 59, '0': 41}, {'0': 60, '1': 40}, {'0': 56, '1': 44}, {'1': 46, '0': 54}, {'0': 46, '1': 54}, {'0': 53, '1': 47}, {'1': 52, '0': 48}, {'0': 49, '1': 51}, {'1': 55, '0': 45}, {'1': 51, '0': 49}, {'1': 48, '0': 52}, {'0': 53, '1': 47}, {'0': 56, '1': 44}, {'1': 53, '0': 47}, {'0': 51, '1': 49}, {'0': 45, '1': 55}, {'1': 47, '0': 53}, {'1': 55, '0': 45}]

That’s not entirely true, since your output shows a list containing dicts, which will still fail if you call .values() or keys() on it.

According to this error, how should I make the changes in my code?

Make sure to pass a dict to this method, not a list.