I am getting an error saying "dict_key object does not support indexing" at:
return len(G[G.keys()[0]])
I realised it used to work in python 2.7.x but not in python 3.How should i change this statement to make it work in python 3.
In Python 2.x, G.keys()
returns a list, but Python 3.x returns a dict_keys
object instead. The solution is to wrap G.keys()
with call to list()
, to convert it into the correct type:
return len(G[list(G.keys())[0]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With