GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python Dictionary items() method - GeeksforGeeks Python Dictionary items() methodLast Updated : 17 Feb, 2026 dict.items() method in Python returns a view object containing all key-value pairs of the dictionary as tuples. This view updates automatically when the dictionary is modified. It is used when both keys and values are required together. Example: In this example, items() is used to retrieve all key-value pairs from a dictionary.
Output dict_items([('A', 'Python'), ('B', 'Java')])
Explanation: d.items() returns a view object containing tuples of key and value pairs from d.
Syntax
ExamplesExample 1: In this example, items() is used inside a loop to access keys and values together. This allows processing both elements in each iteration.
Output x 10 y 20 Explanation: d.items() returns key-value tuples and for k, v in d.items() unpacks each tuple into k and v. Example 2: In this example, dictionary is modified after calling items(). The view object reflects the updated content automatically.
Output dict_items([('a', 1), ('b', 2), ('c', 3)])
Explanation: it = d.items() creates a view object, d['c'] = 3 updates the dictionary and 'it' automatically reflects the new pair. Example 3: In this example, view object returned by items() is converted into a list. This allows using list operations.
Output [('p', 100), ('q', 200)]
Explanation: d.items() returns a view object and list(d.items()) converts it into a list of tuples. Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |