This post is to inform you of an issue with dict_keys. The object does not support indexing. This is a common mistake I have seen users make. They think it does and try to access the values with an index like so: – value = dict_keys[‘key’] + # Try this at your own risk! Value not guaranteed.. + value = dict_keys[0] This will not work because dict_keys is a dictionary of hashes. It does not support indexing, so the above code will raise an error when you try to access it with 0 . Instead use this: – value = list(dict_keys) [-0] + # This works! + value = dict_keys[-0] The second line properly indexes into the object and returns the first item in the list which should be what you’re looking for. Note that -0 converts your int (or whatever type your keys are) to a string which makes sense since we are working with strings within our hash here. The original post has been published from my blog at learnpythonandprogworld/blog. You can also read more about it on my website learnpythonandprogworld.com where I post tutorials, projects and articles related to programming everyday! – See more at: learnpythonandprogworld/blog. – *Also read about it on my website: learnpythonandprogworld/blog.* – This post has been published from my blog at learnpythonandprogworld/blog. You can also check out more articles, projects and tutorials related to programming everyday! Lastly, you can connect with me on Twitter @learncodewithme or LinkedIn linkedin.com/company/3148895 for updates regarding new posts and other random stuff I do outside of the world of programming. Thanks again for reading this article 🙂 See ya next time! – Continue writing.. + You can also read more about it on my website: learnpythonandprogworld/blog.\ + Also check out more articles, projects and tutorials related to programming everyday! Lastly, you can connect with me on Twitter @learncodewithme or LinkedIn linkedin.com/company/3148895 for updates regarding new posts and other random stuff I do outside of the world of programming. Thanks again for reading this article 🙂 See ya next time! + Continue writing.. – You can also read more about it on my website: learnpythonandprogworld/blog. Also check out more articles, projects and tutorials related to programming everyday! Lastly, you can connect with me on Twitter @learncodewithme or LinkedIn linkedin.com/company/3148895 for updates regarding new posts and other random stuff I do outside of the world of programming. Thanks

LEAVE A REPLY

Please enter your comment!
Please enter your name here