{"id":3768,"date":"2023-10-24T16:19:30","date_gmt":"2023-10-24T10:49:30","guid":{"rendered":"https:\/\/python-programs.com\/?p=3768"},"modified":"2023-11-10T11:57:29","modified_gmt":"2023-11-10T06:27:29","slug":"python-iterate-over-dictionary-with-index","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-iterate-over-dictionary-with-index\/","title":{"rendered":"Python: Iterate Over Dictionary with Index"},"content":{"rendered":"

Dictionaries are the implementation by Python of\u00a0a knowledge\u00a0<\/span>structure associative array. A dictionary is a collection of pairs of key values. A key pair and its associated value represent each key pair.
\nThe list of key value pairs in curly braces\u00a0that’s\u00a0<\/span>separated by comma defines a dictionary. Column \u2018:\u2019 separates the value of each key.
\nA dictionary\u00a0can’t be\u00a0<\/span>sorted only\u00a0to urge\u00a0<\/span>a representation of the sorted dictionary. Inherently, dictionaries are orderless, but not other types, including lists and tuples. Therefore,\u00a0you would like\u00a0<\/span>an ordered data type, which\u00a0may be a\u00a0<\/span>list\u2014probably\u00a0an inventory\u00a0<\/span>of tuples.<\/p>\n

Examples:<\/strong><\/p>\n

Input :<\/strong><\/p>\n

dictionary = {'This': 100, 'is':200, 'BTechGeeks':300}<\/pre>\n

Output:<\/strong><\/p>\n

index = 0  ; key = this  ; Value = 200\r\nindex = 1  ; key = is  ; Value = 100\r\nindex = 2  ; key = BTechGeeks  ; Value = 300<\/pre>\n

Traverse the Dictionary with Index<\/h2>\n