I am trying to list through such a dictionary, but it does not work. What is the easiest way to iterate through a dictionary in python when listing each entry?
for i, k, v in enumerate(my_dict.iteritems()): print i, k, v
You just need to add the brackets around the (k, v)tuple:
(k, v)
>>> d = {1: 'foo', 2: 'bar'} >>> for i, (k, v) in enumerate(d.iteritems()): ... print i, k, v ... 0 1 foo 1 2 bar
Source: https://habr.com/ru/post/1659303/More articles:List printed as String in Elixir - elixirGet the value of weights and offsets from the RNN cell - tensorflowUsing static class variables without highlighting them - c ++How can I extend the Array class in Babel? - javascriptOffset of an unsorted shifted array - sortinghow to add the contents of a parent class method to a subclass method - python% matplotlib inline: object 'NoneType' does not have attribute 'is_interactive' - pythonLife episode - rustAngular md-nav-bar stuff doesn't work properly with ui-router - javascriptHow to simulate a list of "index" versus "show" in GraphQL? - restAll Articles